从VS2013 Windows窗体写入/更新DB字段 [英] Write/update DB field from VS2013 windows form
本文介绍了从VS2013 Windows窗体写入/更新DB字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要尝试的是查询特定字段的特定值.如果字段值和输入值相等,那么我希望在找到相等"匹配的同一行中将另一个字段从True更新为False.
还有,
这是通过button_click事件来调用的.
我尝试过的事情:
What I am trying to do is query a specific field for a specific value. If the field value and input value are equal then I want another field updated from True to False within that same row where the "equal" match was found.
Also,
This is called upon with a button_click event.
What I have tried:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connStr As String
connStr = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=C:\Tech\LoanerTracking.accdb"
Dim objConn As New OleDbConnection(connStr)
Dim str As String
str = "Select AssetBarcode from TrackingInfo Where (AssetBarcode=TextBox3 AND CheckedOut=True);"
Dim chg As String
chg = "Select CheckedOut from TrackingInfo where AssetBarcode=TextBox3"
Dim cmd As OleDbCommand = New OleDbCommand(str)
cmd.Connection = objConn
objConn.Open()
Try
If str = TextBox3.Text Then
chg = False
End If
objConn.Close()
MsgBox("Item Successfully Checked-In")
Catch ex As Exception
MsgBox(ex.Message)
End Try
TextBox3.Text = String.Empty
TextBox2.Text = String.Empty
TextBox1.Text = String.Empty
End Sub
推荐答案
自 ^ ] ?!
How have you forgotten how to execute a query and pass a parameter since yesterday[^]?!
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Tech\LoanerTracking.accdb"
Using conn As New OleDbConnection(connStr)
Dim query As String = "Update TrackingInfo Set CheckedOut = 0 WHERE AssetBarcode = ? And CheckedOut = 1"
Using cmd As New OleDbCommand(query, conn)
cmd.Parameters.AddWithValue("?", TextBox3.Text)
Try
conn.Open()
cmd.ExecuteNonQuery()
MsgBox("Item Successfully Checked-In")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Using
End Using
TextBox3.Text = String.Empty
TextBox2.Text = String.Empty
TextBox1.Text = String.Empty
End Sub
这篇关于从VS2013 Windows窗体写入/更新DB字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文