我一直很难为我的问题找到解决方案,我想在我的 ListBox 中用 SQL 显示我的 DB 上的所有列......有人知道吗?请帮帮我?
这是我的代码:
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Try
Dim thisConnection As New SqlConnection("Data Source=#####;Initial Catalog=####;Persist Security Info=True;User ID=#####;Password=#####")
thisConnection.Open()
Dim sql As String = ("SELECT ControlNo,EmpNo,CheckOutDate,CheckOutTime,TaxiNo,PlateNo,Model,Make FROM dbo.ChkInOut WHERE ControlNo='" & txtsearch.Text & "'")
Dim da As New SqlDataAdapter(sql, thisConnection)
da.Fill(ds, "dbo.ChkInOut")
Dim dt As DataTable = ds.Tables("dbo.ChkInOut")
ListBox1.DataSource = dt
ListBox1.DisplayMember = ("ControlNo")
txtCtrlNo.DataBindings.Add("text", dt, "ControlNo")
txtEmpNo.DataBindings.Add("text", dt, "EmpNo")
txtCheckOutDate.DataBindings.Add("text", dt, "CheckOutDate")
txtCheckOutTime.DataBindings.Add("text", dt, "CheckOutTime")
txtTaxiUnitNo.DataBindings.Add("text", dt, "TaxiNo")
txtPlateNo.DataBindings.Add("text", dt, "PlateNo")
txtModel.DataBindings.Add("text", dt, "Model")
txtMake.DataBindings.Add("text", dt, "Make")
thisConnection.Close()
Catch ex As Exception
End Try
End Sub