我的應用程序的目的是,當用戶輸入一個客戶,他們的用戶名和消息到各自的文本框中時,應該在用戶按下發送按鈕後將其記錄到SQL Server上的表中。如何擺脫此錯誤:未在ConnectionString中指定OLE DB提供程序。一個例子是'Provider = SQLOLEDB'
這裏是我的代碼:
Public Class Form1
Dim Con As OleDbConnection
Dim cmd As New OleDbCommand
Dim conString As String = "Data Source=176.111.555.24;Initial Catalog=MyDatabase;User ID=Username;Password=Password"
Public Sub MessageSent()
Try
Dim con As New OleDbConnection
con.ConnectionString = conString
con.Open()
cmd.Connection = con
cmd.CommandText = "insert into tblmessage(Customer, UserName, Message) values('" & txtCustomer.Text & "', '" & txtUserName.Text & "', '" & rtfMessage.Text & "')"
cmd.ExecuteNonQuery()
con.Close()
MsgBox("Message Sent")
con.Close()
con.Dispose()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
MessageSent()
End Sub
,我發現了以下錯誤:
An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'.
它是什麼,我做錯了,這可怎麼解決。
如果數據庫是SQL Server爲什麼你使用OleDB? – Plutonix
你會如何重寫? – Dave
好的。抱歉!我下次會做得更好! – Dave