SSMS创建数据库
use Sales
go
create table grade
(
学号 int primary key,
姓名 varchar(20) not null,
语文 int,
数学 int,
英语 int
)
insert into grade values(14,'王二',50,90,90)
insert into grade values(15,'刘三',50,90,90)
insert into grade values(16,'张四',50,90,90)
insert into grade values(17,'马五',50,90,90)
select * from grade
打开VS,设计界面
Imports System.Data.SqlClient
Public Class Form1
Dim conn As SqlConnection
Dim da As SqlDataAdapter
Dim ds As New DataSet
Private Function GetConnection() As SqlConnection
Return New SqlConnection(My.Settings.SalesConnectionString)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ds.Tables.Clear()
DataGridView1.DataSource = ds
Dim strComm As String = "Select * from grade where 姓名 like '%" & TextBox1.Text & "%'"
da = New SqlDataAdapter(strComm, GetConnection)
da.Fill(ds, "grade")
DataGridView1.DataSource = ds.Tables("grade")
DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
End Sub
End Class