这是我的代码:
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objconnection As OleDbConnection = New OleDbConnection("Provider=SQLOLEDB;″&″DataSource=localhost;Initial Catalog=mysql;″&″UserID=root;Password=root;")
objconnection.Open()
End Sub
End Class
可是调试的时候会出现异常:
在 System.Data.OleDb.OleDbException 中第一次偶然出现的“System.Data.dll”类型的异常
详细信息是:{"无效的授权说明连接字符串属性无效"}
请问如何解决啊?困在这个问题上好久了。
我没有分了。。抱歉
vb.net连接sql数据库
答案:2 悬赏:40 手机版
解决时间 2021-01-02 23:50
- 提问者网友:杀手的诗
- 2021-01-02 07:05
最佳答案
- 五星知识达人网友:孤独入客枕
- 2021-01-02 08:43
您好:给你个Sql Servers 2000的链接方法参考一下。
Public Shared connectionString As String = “Data Source=SERVERS;Initial Catalog=HL;User ID=sa;Password=pw" providerName="System.Data.SqlClient”
'
'执行SQL语句,返回影响的记录数
'
'SQL语句
'影响的记录数
Public Shared Function ExecuteSql(ByVal SQLString As String) As Integer
Using connection As New SqlConnection(connectionString)
Using cmd As New SqlCommand(SQLString, connection)
Try
connection.Open()
Dim rows As Integer = cmd.ExecuteNonQuery()
Return rows
Catch e As System.Data.SqlClient.SqlException
connection.Close()
Throw e
End Try
End Using
End Using
End Function
希望对您有用!
Public Shared connectionString As String = “Data Source=SERVERS;Initial Catalog=HL;User ID=sa;Password=pw" providerName="System.Data.SqlClient”
'
'执行SQL语句,返回影响的记录数
'
'SQL语句
'
Public Shared Function ExecuteSql(ByVal SQLString As String) As Integer
Using connection As New SqlConnection(connectionString)
Using cmd As New SqlCommand(SQLString, connection)
Try
connection.Open()
Dim rows As Integer = cmd.ExecuteNonQuery()
Return rows
Catch e As System.Data.SqlClient.SqlException
connection.Close()
Throw e
End Try
End Using
End Using
End Function
希望对您有用!
全部回答
- 1楼网友:迟山
- 2021-01-02 08:58
imports system.data
imports system.data.oledb
module module1
public function mdbmytab(byval str_select as string) as datatable
dim conn_mdb as new oledbconnection("provider=microsoft.jet.oledb.4.0; data source=mdb.mdb")
dim cmd as new oledbcommand(str_select, conn_mdb)
dim da as new oledbdataadapter(cmd)
dim mytb as dataset = new dataset
da.fill(mytb, 0)
mdbmytab = mytb.tables(0)
conn_mdb.close()
end function
end module
以上为模块代码
以下为窗体代码:
imports system.data
imports system.data.oledb
public class form1
private sub form1_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
dim mytb as datatable = mdbmytab("select * from 表1")
datagridview1.datasource = mytb
combobox1.displaymember = "姓名"
combobox1.datasource = mytb
end sub
end class
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯