3个回答
展开全部
Dim SqlConn As SqlConnection = New SqlConnection("Data Source=服务器名;Initial Catalog=DataBase;Persist Security Info=True;User ID=sa;Password=123")
Dim ds As SqlStr="select * from table"
Dim SqlDa As SqlDataAdapter = New SqlDataAdapter(SqlStr, SqlConn)
Dim ds As New DataSet
ds.Fill(ds)
dataDridview1.DataSource=ds.tables(0)
这样就可以在dataDridview1里面看到表table的数据了
Dim ds As SqlStr="select * from table"
Dim SqlDa As SqlDataAdapter = New SqlDataAdapter(SqlStr, SqlConn)
Dim ds As New DataSet
ds.Fill(ds)
dataDridview1.DataSource=ds.tables(0)
这样就可以在dataDridview1里面看到表table的数据了
展开全部
你用用这个看看。strConn = "Driver={SQL Server}" & _
";UID=" & StrUse & _
";PWD=" & StrPWD & _
";DataBase=" & StrDB & _
";Server=" & StrServer
";UID=" & StrUse & _
";PWD=" & StrPWD & _
";DataBase=" & StrDB & _
";Server=" & StrServer
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
On Error GoTo ErrConnect
Dim Cn As New SqlConnection
If Cn.State = ConnectionState.Open Then Cn.Close()
Cn.ConnectionString = "Server=" & 服务器名& ";DataBase=" & 数据库名& ";User Id=" & sa & ";Pwd=" & 123456 & ""
Cn.Open()
Exit Sub
ErrConnect:
MsgBox("数据库连接错误," + Err.Description, vbExclamation, "信息")
Dim Cn As New SqlConnection
If Cn.State = ConnectionState.Open Then Cn.Close()
Cn.ConnectionString = "Server=" & 服务器名& ";DataBase=" & 数据库名& ";User Id=" & sa & ";Pwd=" & 123456 & ""
Cn.Open()
Exit Sub
ErrConnect:
MsgBox("数据库连接错误," + Err.Description, vbExclamation, "信息")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询