vb.net 连接sql2005
我是新手,求教vb.net连接SQLServer2005,以数据库test1,数据表test2为例。求详细的步骤。如需要哪些控件,连接数据库,打开数据表。然后在DataG...
我是新手,求教vb.net连接SQL Server 2005 ,以数据库test1,数据表test2为例。求详细的步骤。如需要哪些控件,连接数据库,打开数据表。然后在DataGridView1里面显示出来,表的字段有:姓名,年龄,性别。谢谢了,在线等。如果你们有好的关于“vb.net 连接sql2005”的教程文档的话。可以传给我313333970@qq.com。。我将再加100分
你好,谢谢你的关注。我想要的是代码。谢谢 展开
你好,谢谢你的关注。我想要的是代码。谢谢 展开
展开全部
Public sqlcon As System.Data.SqlClient.SqlConnection
Public sqladapter As System.Data.SqlClient.SqlDataAdapter
Public command As System.Data.SqlClient.SqlCommand
Public ds As System.Data.DataSet
Public dr As System.Data.DataTable
sqlcon = New System.Data.SqlClient.SqlConnection
sqlcon.ConnectionString = "Server=(local); Initial Catalog=test1 ; User ID="数据库sa用户"; Password="数据库密码""
ds = New System.Data.DataSet
dr = New System.Data.DataTable(" test2 ")
ds.Tables.Add(dr)
sqladapter = New System.Data.SqlClient.SqlDataAdapter("select * from test2 ", sqlcon)
sqlcon.Open()
sqladapter.Fill(dr)
sqlcon.Close()
DataGridView1.DataSource = dr
Public sqladapter As System.Data.SqlClient.SqlDataAdapter
Public command As System.Data.SqlClient.SqlCommand
Public ds As System.Data.DataSet
Public dr As System.Data.DataTable
sqlcon = New System.Data.SqlClient.SqlConnection
sqlcon.ConnectionString = "Server=(local); Initial Catalog=test1 ; User ID="数据库sa用户"; Password="数据库密码""
ds = New System.Data.DataSet
dr = New System.Data.DataTable(" test2 ")
ds.Tables.Add(dr)
sqladapter = New System.Data.SqlClient.SqlDataAdapter("select * from test2 ", sqlcon)
sqlcon.Open()
sqladapter.Fill(dr)
sqlcon.Close()
DataGridView1.DataSource = dr
2011-02-12
展开全部
将DataGridView控件拖到窗体上,就会弹出一个向导,按向导操作就可以了。
补充:下面是在DataGrid中显示的代码,你参考下。
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objda As New OleDbDataAdapter("select * from kc", "Provider=Microsoft.Jet.oledb.4.0;Data Source=|datadirectory|\xscj.mdb")
Dim ds As New DataSet
objda.Fill(ds, "kc")
DataGrid1.DataSource = ds.Tables(0)
End Sub
End Class
补充:下面是在DataGrid中显示的代码,你参考下。
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objda As New OleDbDataAdapter("select * from kc", "Provider=Microsoft.Jet.oledb.4.0;Data Source=|datadirectory|\xscj.mdb")
Dim ds As New DataSet
objda.Fill(ds, "kc")
DataGrid1.DataSource = ds.Tables(0)
End Sub
End Class
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你这是vb.net还是c#语言?如果是vb.net,语法全错了
vb.net语法:
me.sqlconnection1.connectionstring = "data source=zr_lonely-pc\sqlexpress;attachdbfilename=|datadirectory|\王瑾 08060037宾馆客房.mdf;integrated security=true;user instance=true"
c#:
this.sqlconnection1.connectionstring = "data source=zr_lonely-pc\\sqlexpress;attachdbfilename=|datadirectory|\\王瑾 08060037宾馆客房.mdf;integrated security=true;user instance=true";
去掉attachdbfilename内容的双引号即可。
vb.net语法:
me.sqlconnection1.connectionstring = "data source=zr_lonely-pc\sqlexpress;attachdbfilename=|datadirectory|\王瑾 08060037宾馆客房.mdf;integrated security=true;user instance=true"
c#:
this.sqlconnection1.connectionstring = "data source=zr_lonely-pc\\sqlexpress;attachdbfilename=|datadirectory|\\王瑾 08060037宾馆客房.mdf;integrated security=true;user instance=true";
去掉attachdbfilename内容的双引号即可。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询