all groups > sql server msde > june 2004 >
You're in the

sql server msde

group:

Parameterized insert



Parameterized insert Daniel
6/30/2004 1:43:53 AM
sql server msde: Hi,

I cant get my parameterized insert to work. I've created a
large table in VB.NET and since I want to insert a lot of
rows into it I thought parameterized insert would be a
good solution.


..CommandText = "INSERT INTO TmpTable (C1,C2) VALUES (?, ?)"
..Parameters.Add("C1", SqlDbType.Int).Value = M1
..Parameters.Add("C2", SqlDbType.Bit).Value = M2
..Connection = cn
..CommandType = CommandType.Text
..ExecuteNonQuery()


When executing this code I get two SqlExceptions on the
last line, stating something like: "Syntax error close
to 'C1' and '?'".

What am I doing wrong?
Any help much appreciated.
/Daniel

Parameterized insert Daniel
6/30/2004 5:30:32 AM
I solved it.

Instead of using '?' I use '@C1'. Like this:

..CommandText = "INSERT INTO TmpTable (C1,C2) VALUES (@C1,
@C2)"
..Parameters.Add("@C1", SqlDbType.Int).Value = M1
..Parameters.Add("@C2", SqlDbType.Bit).Value = M2
..Connection = cn
..CommandType = CommandType.Text
..ExecuteNonQuery()

/Daniel
AddThis Social Bookmark Button