主题:急datagrid中的更新问题
下面的代码运行不报错,就是更新不到数据库
Dim new_yhm As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Dim new_mm As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Dim new_lx As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
Dim updatestring As String
Dim strConn As String
strConn = "Server=MS-C8749356387F;database=pubs;trusted_connection=yes"
myConn = New SqlConnection(strConn)
updatestring = "update yhxx1 set yhm=@yhm,mm=@mm,lx=@lx where id=" & DataGrid1.DataKeys(e.Item.ItemIndex)
Dim myCmd1 As SqlCommand = New SqlCommand(updatestring, myConn)
myCmd1.Parameters.Add("@yhm", SqlDbType.VarChar, 50).Value = new_yhm
myCmd1.Parameters.Add("@mm", SqlDbType.VarChar, 50).Value = new_mm
myCmd1.Parameters.Add("@lx", SqlDbType.VarChar, 50).Value = new_lx
myConn.Open()
myCmd1.ExecuteNonQuery()
myConn.Close()
DataGrid1.EditItemIndex = -1
bind_data()
Dim new_yhm As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Dim new_mm As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Dim new_lx As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
Dim updatestring As String
Dim strConn As String
strConn = "Server=MS-C8749356387F;database=pubs;trusted_connection=yes"
myConn = New SqlConnection(strConn)
updatestring = "update yhxx1 set yhm=@yhm,mm=@mm,lx=@lx where id=" & DataGrid1.DataKeys(e.Item.ItemIndex)
Dim myCmd1 As SqlCommand = New SqlCommand(updatestring, myConn)
myCmd1.Parameters.Add("@yhm", SqlDbType.VarChar, 50).Value = new_yhm
myCmd1.Parameters.Add("@mm", SqlDbType.VarChar, 50).Value = new_mm
myCmd1.Parameters.Add("@lx", SqlDbType.VarChar, 50).Value = new_lx
myConn.Open()
myCmd1.ExecuteNonQuery()
myConn.Close()
DataGrid1.EditItemIndex = -1
bind_data()