更新SQL记录是遇到的问题
ProtectedSubdg1_UpdateCommand(ByValsourceAsObject,ByValeAsSystem.Web.UI.WebControls.D...
Protected Sub dg1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg1.UpdateCommand
Dim cnn As New SqlConnection("Data Source=localhost;Initial Catalog=cdshop;Integrated Security=True")
Dim strSql As String
Dim pID, pName, pLei, pInfo, pPrice, pSale As TextBox
pID = e.Item.Cells(0).Controls(0)
pName = e.Item.Cells(1).Controls(0)
pLei = e.Item.Cells(2).Controls(0)
pInfo = e.Item.Cells(3).Controls(0)
pPrice = e.Item.Cells(4).Controls(0)
pSale = e.Item.Cells(5).Controls(0)
strSql = "Update Products Set ProductID='" & pID.Text & "',ProductName='" & pName.Text & "',CategoryID=" & CInt(pLei.Text) & ",Description='" & pInfo.Text & "',UnitPrice='" & pPrice.Text & "',OnSale='" & pSale.Text & "'where ProductNum= " & dg1.DataKeys(CInt(e.Item.ItemIndex))
Dim cmd As New SqlCommand(strSql, cnn)
cnn.Open()
cmd.ExecuteNonQuery()
cnn.Close()
dg1.EditItemIndex = -1
dg1.DataBind()
End Sub
pName.Text字段中的单引号与语句中的单引号混淆 展开
Dim cnn As New SqlConnection("Data Source=localhost;Initial Catalog=cdshop;Integrated Security=True")
Dim strSql As String
Dim pID, pName, pLei, pInfo, pPrice, pSale As TextBox
pID = e.Item.Cells(0).Controls(0)
pName = e.Item.Cells(1).Controls(0)
pLei = e.Item.Cells(2).Controls(0)
pInfo = e.Item.Cells(3).Controls(0)
pPrice = e.Item.Cells(4).Controls(0)
pSale = e.Item.Cells(5).Controls(0)
strSql = "Update Products Set ProductID='" & pID.Text & "',ProductName='" & pName.Text & "',CategoryID=" & CInt(pLei.Text) & ",Description='" & pInfo.Text & "',UnitPrice='" & pPrice.Text & "',OnSale='" & pSale.Text & "'where ProductNum= " & dg1.DataKeys(CInt(e.Item.ItemIndex))
Dim cmd As New SqlCommand(strSql, cnn)
cnn.Open()
cmd.ExecuteNonQuery()
cnn.Close()
dg1.EditItemIndex = -1
dg1.DataBind()
End Sub
pName.Text字段中的单引号与语句中的单引号混淆 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询