vb.net 如何修改数据库内容? 20
ACCESS中的表怎么用VB。NET修改,比如数据库中有一个tUsers的表,表里面有“id”栏,"pw"栏。要通过已知“ID”栏中的数据,修改“PW”栏中的数据,请问怎...
ACCESS 中的表怎么用VB。NET 修改,比如数据库中有一个tUsers的表,表里面有“id”栏,"pw"栏。要通过已知“ID”栏中的数据,修改“PW”栏中的数据,请问怎么能做到?
展开
1个回答
展开全部
Private Function データ修正() As Boolean
Dim strMsg As String = ""
Try
SQL.Length = 0
SQL.AppendLine("update M21_担当者マスタ set")
SQL.AppendLine("パスワード='" & editパスワード.Text & "',")
SQL.AppendLine("where 担当者番号='" & edit社员コード.Text & "'")
strMsg = ExecuteSQLNonQuery(SQL.ToString)
If strMsg <> "" Then
MessageBox.Show(strMsg, "データ修正", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End If
Return True
Catch ex As Exception
MessageBox.Show(ex.Message, "データ修正", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End Try
End Function
Public Function ExecuteSQLNonQuery(ByVal vstrSQL As String) As String
Dim strRet As String = ""
Dim cnn As New SqlClient.SqlConnection(gsConSvr)
Dim cmm As New SqlClient.SqlCommand(vstrSQL, cnn)
'
Try
cnn.Open()
cmm.CommandTimeout = 300
cmm.ExecuteNonQuery()
cnn.Close()
strRet = ""
Catch ex As Exception
strRet = "下记のSQL文を実行するときに、エラーが発生しました。" & vbCrLf
strRet = strRet & "--------------------------------------------" & vbCrLf
strRet = strRet & "【" & vstrSQL & "】" & vbCrLf
strRet = strRet & "--------------------------------------------" & vbCrLf
strRet = strRet & ex.Message
Finally
cnn.Close()
cmm.Dispose()
cmm = Nothing
cnn.Dispose()
cnn = Nothing
End Try
'
Return strRet
End Function
Dim strMsg As String = ""
Try
SQL.Length = 0
SQL.AppendLine("update M21_担当者マスタ set")
SQL.AppendLine("パスワード='" & editパスワード.Text & "',")
SQL.AppendLine("where 担当者番号='" & edit社员コード.Text & "'")
strMsg = ExecuteSQLNonQuery(SQL.ToString)
If strMsg <> "" Then
MessageBox.Show(strMsg, "データ修正", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End If
Return True
Catch ex As Exception
MessageBox.Show(ex.Message, "データ修正", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End Try
End Function
Public Function ExecuteSQLNonQuery(ByVal vstrSQL As String) As String
Dim strRet As String = ""
Dim cnn As New SqlClient.SqlConnection(gsConSvr)
Dim cmm As New SqlClient.SqlCommand(vstrSQL, cnn)
'
Try
cnn.Open()
cmm.CommandTimeout = 300
cmm.ExecuteNonQuery()
cnn.Close()
strRet = ""
Catch ex As Exception
strRet = "下记のSQL文を実行するときに、エラーが発生しました。" & vbCrLf
strRet = strRet & "--------------------------------------------" & vbCrLf
strRet = strRet & "【" & vstrSQL & "】" & vbCrLf
strRet = strRet & "--------------------------------------------" & vbCrLf
strRet = strRet & ex.Message
Finally
cnn.Close()
cmm.Dispose()
cmm = Nothing
cnn.Dispose()
cnn = Nothing
End Try
'
Return strRet
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询