VB连接SQL server 2005数据库
OptionExplicitDimconnAsADODB.ConnectionDimrsAsADODB.RecordsetPrivateSubForm_Load()Set...
Option Explicit
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub Form_Load()
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "Provider=SQLOLEDB.1;Data Source=J:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\stc.mdf;Persist Security Info=true;User ID=sa;Initial Catalog=stc"
conn.Open
rs.Open "student", conn, , adCmdTable
'rs = Execute("select * from student")
Set my.DataSource = rs
rs.Close
conn.Close
End Sub 展开
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub Form_Load()
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "Provider=SQLOLEDB.1;Data Source=J:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\stc.mdf;Persist Security Info=true;User ID=sa;Initial Catalog=stc"
conn.Open
rs.Open "student", conn, , adCmdTable
'rs = Execute("select * from student")
Set my.DataSource = rs
rs.Close
conn.Close
End Sub 展开
3个回答
展开全部
conn.ConnectionString = "Provider=SQLOLEDB.1;Data Source=J:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\stc.mdf;Persist Security Info=true;User ID=sa;Initial Catalog=stc"
这个是错的,应该是
Provider=SQLOLEDB.1;Data Source=这儿应该是IP或是local或是数据库服务名;Persist Security Info=true;User ID=sa;password=pwd; Initial Catalog=stc
这个是错的,应该是
Provider=SQLOLEDB.1;Data Source=这儿应该是IP或是local或是数据库服务名;Persist Security Info=true;User ID=sa;password=pwd; Initial Catalog=stc
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Provider=SQLOLEDB;Data Source=127.0.0.1;UID=帐户;PWD=密码;initial catalog=local
SQL数据库的连接不同于MDB类数据库.
如果无法确定正确与否,可以在VB窗口中临时添加一个ADO控件,利用控件的连接设置可以得到准确的连接字符串.(这是我以前学VB的笨方法,哈)
SQL数据库的连接不同于MDB类数据库.
如果无法确定正确与否,可以在VB窗口中临时添加一个ADO控件,利用控件的连接设置可以得到准确的连接字符串.(这是我以前学VB的笨方法,哈)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询