[吧主][吧主]VB2008怎么连SQL SERVER
vb2008吧
全部回复
仅看楼主
level 5
用控件我知道怎以连接,但我想跟VB6.0一样,用纯代码连接数据库来操作,不知道怎么连,请教!!!
2009年06月10日 03点06分 1
level 0
用System.Data.SQL库
里边包含着SqlConnection
SQLCommand
等等。
具体介绍,可以去看MSDN。
2009年06月10日 09点06分 2
level 6
Sub mysub()
 Dim conn As New SqlConnection() '声明连接
 '设置连接字符串
 conn.ConnectionString = "Data Source=BORED;Initial Catalog=Forward;Persist Security Info=True;User ID=SA;Password=forward"
 conn.Open() '打开连接
 Dim cmd As New SqlCommand
 cmd.CommandType = CommandType.Text
 cmd.CommandText = "select * from userinfo where username = '" & UserNameTextBox.Text & "' and password = '" & PasswordTextBox.Text & "'"
 cmd.Connection = conn
 Dim sqlRead As SqlDataReader = cmd.ExecuteReader
 If sqlRead.Read Then
 ' 下面利用sqlRead来获取数据
 Dim o As Object = sqlRead(0) '获取第一行数据
 End If
 End Sub
2009年06月11日 01点06分 3
1