怎样使用数据连接
以前是使用DELPHI写程序的,现在想学学VB.NET,
查了一些资料还是不明白怎样与数据库连接,请问各位朋友在VB.NET中怎样使用ADO连接SQL SERVER,
并用GRID显示数据,能给个代码例子最好,谢谢!
[解决办法]
dim strconn As String = "data source=127.0.0.1;user id=sa;password=;initial catalog=" Dim cnn As New SqlConnection(strconn)
[解决办法]
Dim CnStr as string = "Server=127.0.0.1;Database=HpZhL;Uid=sa;Pwd=sa"
Cn = New SqlConnection(CnStr)
Cn.Open()
dim SqlS as string
sqls = "Select id,rtrim(KfDjMc) KfDjMc,BzJ from kFDjB order by KfDjMc"
Dim Cmd As SqlCommand
Cmd = Cn.CreateCommand
Cmd.CommandText = SqlS
Dim Ds As New DataSet
Dim DA As New SqlDataAdapter
DA.SelectCommand = Cmd
DA.Fill(Ds, "kFDjLB")
DataGridView1.DataSource = Ds.Tables("kFDjLB")
[解决办法]
忘记与Grid绑定了..
Dim conSet As New SqlConnection("Data source = (local);Initial Catalog = 数据表名;Integrated Security =SSPI;")
Dim comdSet As New SqlCommand
Dim daAdapter As New SqlDataAdapter
Dim dsSet As New DataSet
dim dt as DataTable
comdSet.Connection = cnSet
comdSet.CommandText= "select * from DB中的表名 where ..."
daSet.SelectCommand =cmdSet
cnSet.Open()
daAdapter.Fill(dsSet,"自定义名称")
dt=new DataTable()
dt.DataSource()=dsSet
dt.DataBind()
cnSet.Close()