英文:
How to use binding source filter from one TextBox and Show to another TextBox in vb.net
问题
我有2个文本框,分别是TextBoxITC和TextBoxITM。所以我在TextBoxITC中创建了一个键盘按下事件,所以我想在textboxITM中显示“ITM”列的结果。
谢谢
英文:
I have 2 Textboxes namely TextBoxITC and TextBoxITM. So I've created a keydown event in TextBoxITC so I want to show the result of "ITM" Column in textboxITM.
Thanks
Dim source1 As New BindingSource()
Private Sub PopulateDatatable()
Try
Dim query As String = "Select ITC,ITM FROM IFG WHERE GDN = 'A.04.01.002.001'"
Using con As OleDbConnection = New OleDbConnection(cn)
Using cmd As OleDbCommand = New OleDbCommand(query, con)
Using da As New OleDbDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
da.Dispose()
source1.DataSource = dt
End Using
End Using
End Using
Catch myerror As OleDbException
MessageBox.Show("Error: " & myerror.Message)
Finally
End Try
End Sub
Private Sub TextBoxITC_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBoxITC.KeyDown
If e.KeyCode = Keys.Back Then
source1.Filter = ""
TextBoxITC.Clear()
clearData()
Else
End If
If e.KeyCode = Keys.Enter Then
source1.Filter = "ITC = '" & Replace(TextBoxITC.Text, "'", "") & "'"
If source1.Count <= 0 Then
source1.Filter = ""
TextBoxITC.Clear()
MsgBox("No Result Found!", MsgBoxStyle.Exclamation)
End If
End If
End Sub
答案1
得分: 0
以下是您要翻译的代码部分:
Private Sub TextBoxITC_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBoxITC.KeyDown
If e.KeyCode = Keys.Back Then
source1.Filter = ""
TextBoxITC.Clear()
clearData()
Else
End If
If e.KeyCode = Keys.Enter Then
Using con As OleDbConnection = New OleDbConnection(cn)
con.Open()
Dim query As String = "Select ITM FROM IFG WHERE ITC = ? AND GDN = 'A.04.01.002.001'"
Using command As OleDbCommand = New OleDbCommand(query, con)
command.Parameters.Add("ITC", OleDbType.VarChar).Value = TextBoxITC.Text
Dim result As Object = command.ExecuteScalar()
If result IsNot Nothing Then
TextBoxolditem.Text = result.ToString()
Else
TextBoxolditem.Text = "Number Not found!"
End If
con.Close()
End Using
End Using
End If
End Sub
希望这有所帮助。如果您需要任何进一步的翻译,请告诉我。
英文:
Here's a link! and Answer from @Steve
Private Sub TextBoxITC_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBoxITC.KeyDown
If e.KeyCode = Keys.Back Then
source1.Filter = ""
TextBoxITC.Clear()
clearData()
Else
End If
If e.KeyCode = Keys.Enter Then
Using con As OleDbConnection = New OleDbConnection(cn)
con.Open()
Dim query As String = "Select ITM FROM IFG WHERE ITC = ? AND GDN = 'A.04.01.002.001'"
Using command As OleDbCommand = New OleDbCommand(query, con)
command.Parameters.Add("ITC", OleDbType.VarChar).Value = TextBoxITC.Text
Dim result As Object = command.ExecuteScalar()
If result IsNot Nothing Then
TextBoxolditem.Text = result.ToString()
Else
TextBoxolditem.Text = "Number Not found!"
End If
con.Close()
End Using
End Using
End If
End Sub
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论