how to update data from datagridview with sqldatabse in vb.net

你说的曾经没有我的故事 提交于 2019-12-25 06:59:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!