2012-11-06 53 views
0

我正在研究一個將數據輸入到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,我希望有人可能知道我在這裏做錯了什麼。

在此先感謝

回答

0

嗯,首先:針對SQL服務器精簡版(該*.sdf文件)時,您需要使用SqlCeConnectionSqlCeCommand(不SqlConnectionSqlCommand - 這些都爲全面爆發SQL Server中,非緊湊型)

其次:你INSERT說法是不正確 - 正確的SQL語法是:

INSERT INTO Table (col1, col2, ..., colN) 
VALUES(val1, val2, ..., valN) 
+1

SQLCe連接是問題。萬分感謝。 –