VB.NET操作SQL SERVER 2008数据库,想把文本框中输入的字符串转化为数字进行数据库的更新,却一直失败
更新语句如下:PrivateSubbtUpdate_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)H...
更新语句如下:
Private Sub btUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btUpdate.Click
Dim x As Int16 = Int16.Parse(TxtPerson.Text)
Dim sql As String = "UPDATE COURSEINFO SET REALLENGTH=x WHERE TEACHERID='" + TxtNum.Text + "'"
Dim dt As DataTable = GetDataTable(sql)
Dim sqlCmd As New SqlCommand
sqlCmd.Connection = SqlCon
sqlCmd.CommandText = sql
Try
SqlCon.Open()
sqlCmd.ExecuteNonQuery()
MessageBox.Show("修改记录成功")
Catch ex As Exception
MessageBox.Show("修改记录失败")
WriteErr(ex)
Finally
SqlCon.Close()
End Try
End Sub
End Class
求高手指导为什么一直不成功,更新语句格式有错吗? 展开
Private Sub btUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btUpdate.Click
Dim x As Int16 = Int16.Parse(TxtPerson.Text)
Dim sql As String = "UPDATE COURSEINFO SET REALLENGTH=x WHERE TEACHERID='" + TxtNum.Text + "'"
Dim dt As DataTable = GetDataTable(sql)
Dim sqlCmd As New SqlCommand
sqlCmd.Connection = SqlCon
sqlCmd.CommandText = sql
Try
SqlCon.Open()
sqlCmd.ExecuteNonQuery()
MessageBox.Show("修改记录成功")
Catch ex As Exception
MessageBox.Show("修改记录失败")
WriteErr(ex)
Finally
SqlCon.Close()
End Try
End Sub
End Class
求高手指导为什么一直不成功,更新语句格式有错吗? 展开
2个回答
展开全部
Dim sql As String = "UPDATE COURSEINFO SET REALLENGTH=x WHERE TEACHERID='" + TxtNum.Text + "'"
修改为:
Dim sql As String = "UPDATE COURSEINFO SET REALLENGTH=x WHERE TEACHERID=" & TxtNum.Text
PS:
VB中字符串的连接最好使用&符号,不要使用+符号
修改为:
Dim sql As String = "UPDATE COURSEINFO SET REALLENGTH=x WHERE TEACHERID=" & TxtNum.Text
PS:
VB中字符串的连接最好使用&符号,不要使用+符号
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询