Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB.NET
If Me.DataGridView5.Rows.Count > 0 Then
           If Me.DataGridView5.SelectedRows.Count > 0 Then
               Dim intStdID As String = Me.DataGridView5.SelectedRows(0).Cells(0).Value
               'open connection
               If DataGridView5.Rows.Count = 0 AndAlso DataGridView5.SelectedCells.Count = 0 Then
                   MsgBox("Please select an Account to disable", MsgBoxStyle.Exclamation)
                   Exit Sub
               End If
               If Not cnn.State = ConnectionState.Open Then
                   cnn.Open()
               End If
               'delete data
               Dim cmd As New OleDb.OleDbCommand
               cmd.Connection = cnn
               cmd.CommandText = "DELETE FROM AccAdmin WHERE Username=" & intStdID
               cmd.ExecuteNonQuery()
               'refresh data
               Me.RefreshData()

               'close connection
               cnn.Close()
           End If
       End If


What I have tried:

I'm getting a problem no value given for one or more required parameters
Posted
Updated 25-Oct-16 20:21pm

1 solution

intStdID is a string, which you read from your DataGridView - hence it could contain anything.
When you concatenate strings to form SQL queries, you are doing two things:
1) giving yourself a source of potential problems like this one.
And much more importantly
2) leaving yourself open to SQL Injection attacks, which can damage of destroy your database.

To solve this, use parameterized queries at all times. If you don't, take backups of your dB at regular intervals - I'd suggest every minute or so - because it's not "if" your DB will be damaged, it's "when"
 
Share this answer
 
Comments
CaptainChizni 26-Oct-16 2:47am    
I fix my query, It works thank you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900