SQL SIMPLE CONNECTION

Me.Show()
Dim SQLCon As New SqlConnection With {.ConnectionString = “Server=192.168.1.101;Database=database_alan;User=sa;Pwd=yXXXXXXX;”}

Dim sqltxt As String = “select * from User_Info” ‘定义sql语句

Dim sqlcmd As New SqlCommand(sqltxt, SQLCon) ‘定义sqlCommand
Dim userReader As SqlDataReader ‘定义sqldatareader
Try
SQLCon.Open() ‘打开连接
userReader = sqlcmd.ExecuteReader ‘生成sqldatareader
userReader.Read() ‘读取数据
MsgBox(userReader.Item(3)) ‘显示读取的第四个数据
userReader.Close() ‘关闭阅读
Catch ex As Exception
MsgBox(ex.Message)
Finally
sqlcmd.Dispose() ‘ 释放sqlCommand
End Try

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *