在VB中怎样连接sql数据库的具体操作?
1、打开代码窗口,添加引用:Imports System.Data.SqlClient。2、输入以下代码:“Public conn1 As SqlConnection = New SqlConnection _("server=192.168.1.79; Initial Catalog= student; User ID= panqe;PWD=shentai768@")”,vb就已经成功连接sql数据库了。3、代码详解:声明关键字Public(因为是全局变量,所以用Public 来声明)。4、连接参数。5、如果SQL 数据库就在本机,则用以下代码连接:("server=.; Integrated Security=False;Initial Catalog= student; User ID= panqe;PWD=shentai768@")。6:如果代码太长,影响可读性,可以用空格加"_"后,回车换行。
vb如何连接sql数据库??
1、打开代码窗口,添加引用:Imports System.Data.SqlClient。2、输入以下代码:“Public conn1 As SqlConnection = New SqlConnection _("server=192.168.1.79; Initial Catalog= student; User ID= panqe;PWD=shentai768@")”,vb就已经成功连接sql数据库了。3、代码详解:声明关键字Public(因为是全局变量,所以用Public 来声明)。4、连接参数。5、如果SQL 数据库就在本机,则用以下代码连接:("server=.; Integrated Security=False;Initial Catalog= student; User ID= panqe;PWD=shentai768@")。6:如果代码太长,影响可读性,可以用空格加"_"后,回车换行。
在vb中如何只用datagrid控件连接数据库并显示出来 要完整的代码
Public cnn As adodb.ConnectionPublic rst As adodb.RecordsetPublic Sub setdb() Set cnn = New adodb.Connection cnn.Provider = "Microsoft.Jet.OLEDB.4.O" cnn.ConnectionString = "Data Source=" & App.Path & "\personal.mdb;" cnn.CursorLocation = adUseClient cnn.OpenEnd SubPrivate Sub Form_Load() On Error Resume Next Dim Strsql As String setdb Set DataGrid1.DataSource = Nothing Strsql = "select * from 备忘录 order by 编号" Set rst = cnn.Execute(Strsql) If Err Then MsgBox "读取数据失败" Exit Sub End If If rst.EOF Then Set DataGrid1.DataSource = Nothing Else Set DataGrid1.DataSource = rst End IfEnd Sub我帮你整理了以下,这样好看一些
VB6.0如何在DATAGRID控件中显示数据库内容啊?
这是我做的一个示例,希望对你有所帮助!!Private conn As ADODB.Connection
Private rsmc As ADODB.RecordsetPrivate Sub Command1_Click()End SubPrivate Sub Command2_Click()
On Error Resume Next
i = MsgBox("是否清空所有历史记录?", vbYesNo + vbInformation, "提示")
If i = vbYes Then
rsmc.MoveFirst
While Not rsmc.EOF
rsmc.Delete
rsmc.MoveNext
Wend
End If
End SubPrivate Sub Command3_Click()
Me.Hide
End SubPrivate Sub Form_Activate()
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\xs.mdb"
conn.Open
Set rsmc = New ADODB.Recordset
rsmc.CursorLocation = adUseClient
rsmc.Open "xtZZ", conn, 2, 2
Set DataGrid1.DataSource = rsmc
DataGrid1.Refresh
End Sub