I’m working on a VB.NET Program that inputs data to a SQL Server CE local database (*.sdf file).
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’.
This is first time I am using VB.NET and I’m hoping someone might know what I’m doing wrong here.
Thanks in advance
Well, for starters: when targeting SQL Server Compact Edition (the
*.sdffile), you need to useSqlCeConnectionandSqlCeCommand(notSqlConnectionorSqlCommand– those are for the full-blown SQL Server, non-compact)Secondly: your
INSERTstatement is incorrect – the correct SQL syntax would be: