问题
i use another form editting data. when i double click the selected row in datagridview it will transfer the data in another form(frmEdit). i use this codes but it seems not working, how can i fix this. please help.
Dim queryEdit As String = String.Empty
queryEdit = "update dataContactDB set con_Name=@Name, con_Phone=@Phone, Address=@Address, Company=@Company, Gender=@Gender.text where con_Phone=txtPhone.text"
Using conn As New SqlConnection(dbFunction.db)
Using comm As New SqlCommand
With comm
.Connection = conn
.CommandType = CommandType.Text
.CommandText = queryEdit
---- is there a error in this part? ------
.Parameters.AddWithValue("@Name", txtName.Text)
.Parameters.AddWithValue("@Phone", txtPhone.Text)
.Parameters.AddWithValue("@Address", txtAddress.Text)
.Parameters.AddWithValue("@Company", txtCompany.Text)
.Parameters.AddWithValue("@Gender", txtGender.Text)
End With
Try
conn.Open()
comm.ExecuteNonQuery()
conn.Close()
loadmyGrid()
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Error Message")
End Try
End Using
End Using[![my error screenshot][1]][1]
来源:https://stackoverflow.com/questions/32369173/how-to-update-data-from-datagridview-with-sqldatabse-in-vb-net