VB.NET 2008中 如何在DataGridView控件中显示数据查询的结果?数据库是SQL Server2008

2024-12-17 03:35:32
推荐回答(2个)
回答1:

LeafSqlCommand = New SqlCommand("Select * from TableMember where 会员姓名= '" & TextBox1.Text & "'", LeafSqlConnection) 你这句是不是写错了啊
LeafSqlCommand = New SqlCommand("Select * from TableMember where 会员姓名= “ & ”‘“ & tBox1.Text & "'", LeafSqlConnection)

回答2:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oledb1 As New OleDb.OleDbConnection
Dim ServerIP as string="127.0.0.1"
oledb1.ConnectionString = "Provider=SQLOLEDB;Data Source=" + ServerIP + ";Initial Catalog=VIPcardDatabase 3;User ID=sa;Password=asd"
oledb1.Open()
If ConnectionState.Open Then
Dim ssql As String
ssql = "Select * from TableMember"
Dim MyAdapter As New OleDb.OleDbDataAdapter(ssql, oledb1)
Dim MyTable As New DataTable()
MyAdapter.Fill(MyTable)
DataGridView1.DataSource = MyTable

oledb1.Close()
'MsgBox("查询成功")
End If
End Sub