|
Forums » .NET » Windows »
|
I can't change the value in the datagridview. |
Posted Date: 07 Jul 2012 Posted By:: John Member Level: Bronze Member Rank: 1736 Points: 5
Responses:
1
|
Dear Forummembers, I have a problem with changing the data in my datagridview.
I want to give the user the possibility to change a column in the view. I'll do this with the following code:
Dim Updatecmd As SqlCommand = Cnst.CreateCommand
Updatecmd.CommandText = "Update Klant Set Klant.Naamvoornaam=@Naamvoornaam, Klant.Adres=@Adres, Klant.Huisnummer=@Huisnummer, Klant.Telefoonnummer=@Telefoonnummer, Klant.GSMnummer=@GSMnummer, Klant.Email=@Email, Klant.KlantMaat=@Klantmaat, Klant.TeGoed=@TeGoed where Klantnummer=@Klantnummer"
Updatecmd.Parameters.AddWithValue("Klantnummer", ComboBox1.SelectedValue)
Updatecmd.Parameters.Add("Naamvoornaam", SqlDbType.NVarChar, 40, "Naamvoornaam")
Updatecmd.Parameters.Add("Adres", SqlDbType.NVarChar, 40, "Adres")
Updatecmd.Parameters.Add("Huisnummer", SqlDbType.NVarChar, 15, "Huisnummer")
Updatecmd.Parameters.Add("Telefoonnummer", SqlDbType.NVarChar, 15, "Telefoonnummer")
Updatecmd.Parameters.Add("GSMnummer", SqlDbType.NVarChar, 15, "GSMnummer")
Updatecmd.Parameters.Add("Email", SqlDbType.NVarChar, 50, "Email")
Updatecmd.Parameters.Add("Klantmaat", SqlDbType.NVarChar, 75, "Klantmaat")
Dim I As Integer
For I = 0 To DataGridView1.Rows.Count - 1
Dim TeGoed As String = CStr(DataGridView1.Rows(I).Cells(11).Value)
If (CDbl(TeGoed) <= 0) Then
Updatecmd.Parameters.Add("TeGoed", SqlDbType.NVarChar, 75, "TeGoed")
Else
MessageBox.Show(" You have to fill in a negative value (TeGoed = - 'getal') ")
Exit Sub
End If
Next
DaKlant.UpdateCommand = Updatecmd
DaKlant.Update(TaKlant)
Debugging gives me the following message:
The variable name '@TeGoed' has already been declared. Variable names must be unique within a query batch or stored procedure.
I've searched and tried, but couldn't find a solution?
Somebody can take a look ?
John
|
Responses
|
|
|
| Post Reply |
|
|
|
 | | This thread is locked for new responses. Please post your comments and questions as a separate thread. If required, refer to the URL of this page in your new post. |
|
|
|
|
 Follow us on Twitter: https://twitter.com/dotnetspider
|
|