vb.net 将数据插入到 SQL Server Compact
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13245423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Insert Data to SQL Server Compact
提问by Morgan Green
I'm working on a VB.NET Program that inputs data to a SQL Server CE local database (*.sdffile).
我正在开发一个将数据输入到 SQL Server CE 本地数据库(*.sdf文件)的 VB.NET 程序。
My code is this:
我的代码是这样的:
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
I get three errors during compile:
我在编译过程中遇到三个错误:
Error 1: Argument not specified for parameter 'connection' of 'Public Sub New(cmdText As String, connection As System.Data.SqlClient.SqlConnection, transaction As System.Data.SqlClient.SqlTransaction)'.
Error 2
Comma, ')', or a valid expression continuation expected.Error 3
Value of type 'System.Data.SqlClient.SqlConnection' cannot be converted to 'System.Data.SqlClient.SqlTransaction'.
错误 1:未为“Public Sub New(cmdText As String,connection As System.Data.SqlClient.SqlConnection,transaction As System.Data.SqlClient.SqlTransaction)”的参数“connection”指定参数。
错误 2
逗号、“)”或预期的有效表达式继续。错误 3
类型“System.Data.SqlClient.SqlConnection”的值无法转换为“System.Data.SqlClient.SqlTransaction”。
This is first time I am using VB.NET and I'm hoping someone might know what I'm doing wrong here.
这是我第一次使用 VB.NET,我希望有人知道我在这里做错了什么。
Thanks in advance
提前致谢
采纳答案by marc_s
Well, for starters: when targeting SQL Server CompactEdition (the *.sdffile), you need to use SqlCeConnectionand SqlCeCommand(not SqlConnectionor SqlCommand- those are for the full-blown SQL Server, non-compact)
好吧,对于初学者:当针对 SQL Server CompactEdition(*.sdf文件)时,您需要使用SqlCeConnection和SqlCeCommand(不是SqlConnection或SqlCommand- 那些是针对成熟的 SQL Server,非紧凑型)
Secondly: your INSERTstatement is incorrect - the correct SQL syntax would be:
其次:您的INSERT语句不正确 - 正确的 SQL 语法是:
INSERT INTO Table (col1, col2, ..., colN)
VALUES(val1, val2, ..., valN)

