vb2008链接到sql及Access的代码示例
实例是最好的入门:http://dl.dbank.com/c09u9k9iys
ASP/Visual Basic Code复制内容到剪贴板
- Public Class Form1
- ' Declare objects...
- Dim objConnection As New SqlConnection _
- ("server=supervisor;database=pubs;user id=sa;password=123;")
- Dim objDataAdapter As New SqlDataAdapter( _
- "SELECT authors.au_id, au_lname, au_fname, " & _
- "titles.title_id, title, price " & _
- "FROM authors " & _
- "JOIN titleauthor ON authors.au_id = titleauthor.au_id " & _
- "JOIN titles ON titleauthor.title_id = titles.title_id " & _
- "ORDER BY au_lname, au_fname", objConnection)
- Dim objDataSet As DataSet
- Dim objDataView As DataView
- Dim objCurrencyManager As CurrencyManager
如果链接过程中出现错误:未处理sqlException 请检查这行
Dim objConnection As New SqlConnection _
("server=supervisor;database=pubs;user id=sa;password=123;") ’其中加粗部分参数根据情况修改
ADO.net 连接access两种方法
Dim connectionstring As String = "Provider =Microsoft.Jet.OLEDB.4.0;Data Source=" & My.Application.Info.DirectoryPath & "\dataname.mdb;" 'OLEDB
Dim connectionstring As String = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & My.Application.Info.DirectoryPath & "\dataname.mdb" 'Odbc