C
Charles A. Lackman
Hello,
I have written quite a few programs that use Jet4.0 databases. I just
recently updated to SQL Server and have run into a problem with sending
Insert commands.
Using OleDb this works with no problems against Jet 4.0 and dBase and other
databases, but I get an exception when i use this against SQL Server (MSDE).
The error is happening lin line Number 2:
IE: Incorrent syntax near "?"
If I don't use parameters and simply change the CommandText to:
INSERT INTO TESTING VALUES ('One', 'Two',
'Three', 'Four', 'Five')
it works with the value One thru Five in each column.
Any Ideas??
1 Dim SQLCommand As New SqlClient.SqlCommand()
2 SQLCommand.CommandText = "INSERT INTO TESTING VALUES(?,?,?,?,?)"
3 SQLCommand.Connection = SQLConnection
4 SQLCommand.Parameters.Add("@One", SqlDbType.Char)
5 SQLCommand.Parameters(0).Value = TextBox1.Text
6 SQLCommand.Parameters.Add("@Two", SqlDbType.Char)
7 SQLCommand.Parameters(1).Value = TextBox2.Text
8 SQLCommand.Parameters.Add("@Three", SqlDbType.Char)
9 SQLCommand.Parameters(2).Value = TextBox3.Text
10 SQLCommand.Parameters.Add("@Four", SqlDbType.Char)
11 SQLCommand.Parameters(3).Value = TextBox4.Text
12 SQLCommand.Parameters.Add("@Five", SqlDbType.Char)
13 SQLCommand.Parameters(4).Value = TextBox5.Text
14 Try
15 SQLConnection.Open()
16 SQLCommand.ExecuteNonQuery()
17 SQLConnection.Close()
18 Catch errr As SqlClient.SqlException
19 MessageBox.Show(errr.ToString)
20 SQLConnection.Close()
21 Catch err As Exception
22 MessageBox.Show(err.ToString)
23 SQLConnection.Close()
24 End Try
Thanks,
Chuck
I have written quite a few programs that use Jet4.0 databases. I just
recently updated to SQL Server and have run into a problem with sending
Insert commands.
Using OleDb this works with no problems against Jet 4.0 and dBase and other
databases, but I get an exception when i use this against SQL Server (MSDE).
The error is happening lin line Number 2:
IE: Incorrent syntax near "?"
If I don't use parameters and simply change the CommandText to:
INSERT INTO TESTING VALUES ('One', 'Two',
'Three', 'Four', 'Five')
it works with the value One thru Five in each column.
Any Ideas??
1 Dim SQLCommand As New SqlClient.SqlCommand()
2 SQLCommand.CommandText = "INSERT INTO TESTING VALUES(?,?,?,?,?)"
3 SQLCommand.Connection = SQLConnection
4 SQLCommand.Parameters.Add("@One", SqlDbType.Char)
5 SQLCommand.Parameters(0).Value = TextBox1.Text
6 SQLCommand.Parameters.Add("@Two", SqlDbType.Char)
7 SQLCommand.Parameters(1).Value = TextBox2.Text
8 SQLCommand.Parameters.Add("@Three", SqlDbType.Char)
9 SQLCommand.Parameters(2).Value = TextBox3.Text
10 SQLCommand.Parameters.Add("@Four", SqlDbType.Char)
11 SQLCommand.Parameters(3).Value = TextBox4.Text
12 SQLCommand.Parameters.Add("@Five", SqlDbType.Char)
13 SQLCommand.Parameters(4).Value = TextBox5.Text
14 Try
15 SQLConnection.Open()
16 SQLCommand.ExecuteNonQuery()
17 SQLConnection.Close()
18 Catch errr As SqlClient.SqlException
19 MessageBox.Show(errr.ToString)
20 SQLConnection.Close()
21 Catch err As Exception
22 MessageBox.Show(err.ToString)
23 SQLConnection.Close()
24 End Try
Thanks,
Chuck