datagrid更新数据库问题,在线等待
其中 conn 已经定义了
Dim updateCmd As String = "UPDATE 菜单 SET 菜名=@Id,单价=@password,折扣=@uname,大类=@sex WHERE 菜名=@Id;"
Dim myCommand As SqlCommand = New SqlCommand(updateCmd, conn)
myCommand.Parameters.Add(New SqlParameter("@Id", SqlDbType.VarChar, 18))
myCommand.Parameters.Add(New SqlParameter("@password", SqlDbType.Decimal, 8))
myCommand.Parameters.Add(New SqlParameter("@uname", SqlDbType.Decimal, 9))
myCommand.Parameters.Add(New SqlParameter("@sex", SqlDbType.VarChar, 18))
myCommand.Parameters("@Id").Value = DataGrid1.DataKeys(e.Item.ItemIndex).ToString
Dim textbox As TextBox
textbox = CType(e.Item.Cells(3).Controls(0), TextBox)
myCommand.Parameters("@password").Value = System.Convert.ToDecimal(textbox.Text)
textbox = CType(e.Item.Cells(4).Controls(0), TextBox)
myCommand.Parameters("@uname").Value = System.Convert.ToDecimal(textbox.Text)
textbox = CType(e.Item.Cells(5).Controls(0), TextBox)
myCommand.Parameters("@sex").Value = textbox.Text
' 连接数据库,更新数据
' myCommand.Connection.Open()
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim a As Integer
Try
a = myCommand.ExecuteNonQuery()
Catch ex As SqlException
Response.Write(ex.ToString)
End Try
Response.Write(a)
DataGrid1.EditItemIndex = -1
'关闭连接,重新绑定数据库
' myCommand.Connection.Close()
conn.Close()
mycommand.executenonquery()成功执行,并返回1(a=1)但数据库却没有更改到,请问那里有问题,谢谢.