我正在研究一個將數據輸入到SQL Server CE本地數據庫(*.sdf
文件)的VB.NET程序。插入數據到SQL Server Compact
我的代碼是這樣的:
Imports System.Data.SqlClient
Public Class Form1
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim ra As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myConnection = New SqlConnection("Data Source= Database1.sdf")
myConnection.Open()
myCommand = New SqlCommand("Insert into website('"TextBox1.Text"')", myConnection)
ra = myCommand.ExecuteNonQuery()
MessageBox.Show("Updated")
myConnection.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = My.Settings.SaveWebsite
End Sub
End Class
我編譯過程中得到三個錯誤:
錯誤1:爲「公共的Sub New(聲明cmdtext參數 '連接' 作爲字符串沒有指定 參數,連接爲 System.Data.SqlClient.SqlConnection,事務爲 System.Data.SqlClient.SqlTransaction)'。
錯誤2
逗號,')'或預期的有效表達式延續。錯誤3
類型'System.Data.SqlClient.SqlConnection'的值無法轉換爲'System.Data.SqlClient.SqlTransaction'。
這是我第一次使用VB.NET,我希望有人可能知道我在這裏做錯了什麼。
在此先感謝
SQLCe連接是問題。萬分感謝。 –