Help needed with Parameters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm getting an INSERT INTO SQL error. Any ideas?
Thanks a ton,
Boggie

odbcConnection1.Open();
OdbcCommand myCommand = new OdbcCommand("INSERT INTO Listgroup (Newsgroups,
Message-ID) VALUES (?)", odbcConnection1);
myCommand.Parameters.Add("", OdbcType.Text).Value = endstring;
myCommand.ExecuteNonQuery();
odbcConnection1.Close();

Error: Syntax error in INSERT INTO statement.
endstring= "Message-ID: <[email protected]>, Newsgroups:
microsoft.public.access"
myCommand
CommandText="INSERT INTO Listgroup (Newsgroups, Message-ID) VALUES (?)"
Parameter.Count=1

The final string I'm looking at executing would be:
"INSERT INTO Listgroup (Newsgroups, Message-ID) VALUES (Message-ID:
<[email protected]>, Newsgroups: microsoft.public.access)"
 
Boggie,

The problem is that you are not specifiying two values to correspond to
the two fields that you have in the insert statement. You have just one
parameter.

You want to add a second question mark and add the parameter and the
value.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Boggie said:
I'm getting an INSERT INTO SQL error. Any ideas?
Thanks a ton,
Boggie

odbcConnection1.Open();
OdbcCommand myCommand = new OdbcCommand("INSERT INTO Listgroup (Newsgroups,
Message-ID) VALUES (?)", odbcConnection1);
myCommand.Parameters.Add("", OdbcType.Text).Value = endstring;
myCommand.ExecuteNonQuery();
odbcConnection1.Close();

Error: Syntax error in INSERT INTO statement.
endstring= "Message-ID: <[email protected]>, Newsgroups:
microsoft.public.access"
myCommand
CommandText="INSERT INTO Listgroup (Newsgroups, Message-ID) VALUES (?)"
Parameter.Count=1

The final string I'm looking at executing would be:
"INSERT INTO Listgroup (Newsgroups, Message-ID) VALUES (Message-ID:
<[email protected]>, Newsgroups:
microsoft.public.access)"
 
I added a second question mark and get the error:
COUNT field incorrect

I don't think adding another parameter statement is the answer because then
I'd have the same string doubled. The string has been put together earlier
in the program. I thought I could use any combination of strings in just one
parameter statement and that it would work as long as it corresponded with
the number of columns.
for instance
INSERT INTO Listgroup (Newsgroups) Values (?) // where ? =
microsoft.public.access
or
INSERT INTO Listgroup (Newsgroups, Message-ID) Values (?) // where ? =
microsoft.public.access, abcdef@12345

Thanks for your help,
Boggie

Nicholas Paldino said:
Boggie,

The problem is that you are not specifiying two values to correspond to
the two fields that you have in the insert statement. You have just one
parameter.

You want to add a second question mark and add the parameter and the
value.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Boggie said:
I'm getting an INSERT INTO SQL error. Any ideas?
Thanks a ton,
Boggie

odbcConnection1.Open();
OdbcCommand myCommand = new OdbcCommand("INSERT INTO Listgroup (Newsgroups,
Message-ID) VALUES (?)", odbcConnection1);
myCommand.Parameters.Add("", OdbcType.Text).Value = endstring;
myCommand.ExecuteNonQuery();
odbcConnection1.Close();

Error: Syntax error in INSERT INTO statement.
endstring= "Message-ID: <[email protected]>, Newsgroups:
microsoft.public.access"
myCommand
CommandText="INSERT INTO Listgroup (Newsgroups, Message-ID) VALUES (?)"
Parameter.Count=1

The final string I'm looking at executing would be:
"INSERT INTO Listgroup (Newsgroups, Message-ID) VALUES (Message-ID:
<[email protected]>, Newsgroups:
microsoft.public.access)"
 
Back
Top