16,553
社区成员
发帖
与我相关
我的任务
分享
Public SqlCon As New SqlConnection("server=aa63c80319914df;initial catalog=SAMPLE02;User Id=wanglei;Pwd=wanglei")
Dim constr As String = "User ID=wanglei;pwd=wanglei;Initial Catalog=SAMPLE02;Data Source=(local)" '定义一个变量,连接字符串
Dim sqlstr As String = "select * from DB" '定义一个变量,SQL语句里的DB为你的一个表
Dim mycon As New SqlConnection(constr) '定义一个变量,为一个连接对象
Dim mycom As New SqlCommand(sqlstr, mycon) '定义一个变量,为命令对象
Dim myReader As SqlDataReader '定义一个变量,阅读器
mycon.Open() '打开这个联接
myReader = mycom.ExecuteReader '把这个命令的连接送入阅读器
myReader.Read '用阅读器的read的方法来读
MsgBox(myReader(0))
Dim SqlCon As New SqlConnection("Data Source=aa63c80319914df;Initial Catalog=SAMPLE02;User Id=wanglei;wanglei=")
'或者
Dim SqlCon As New SqlConnection("server=aa63c80319914df;Database=SAMPLE02;User Id=wanglei;Pwd=wanglei")
Dim SqlCon As New SqlConnection("server=aa63c80319914df;Database=SAMPLE02;User Id=wanglei;Pwd=wanglei")