我有一個文本框和一個數據網格。我試圖在文本框中輸入一個姓氏,並將那個姓氏的整個記錄從oracle數據庫中返回到datagrid中。下面的代碼當前返回表中的所有記錄,而不是按姓氏搜索。VB.net/Oracle從文本框中選擇語句輸入到datagrid中
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myString As String
Dim myArg As String
Dim mysql As String
Dim myConn As New OleDb.OleDbConnection()
' Create new connection
myString = "Provider=msdaora;Data Source=XXXX;User Id=XXXX;Password=XXXX;"
myConn.ConnectionString = myString
myArg = TextBox1.Text
mysql = "select * from table1 where lastname like '%'"
Try
myConn.Open()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Dim myDataadapter As New OleDb.OleDbDataAdapter(mysql, myConn)
Dim myDs As New DataSet
myDataadapter.Fill(myDs, "customer")
Dim prmLName As New OleDb.OleDbParameter()
prmLName.Direction = ParameterDirection.Input
prmLName.Size = "10"
prmLName.Value = TextBox1.Text
DataGridView1.DataSource = myDs
DataGridView1.DataMember = "customer"
End Sub
End Class
感謝您的幫助和建議,在此! – Christopher
歡迎:) – Muse