nathan

nathan

  • NA
  • 15
  • 0

ODBC Command Problems

Nov 13 2006 5:35 AM
Hi,

I'm new to connecting to DB's and i'm playing with a test DB and trying to insert a record. My code runs but always gives errors, i've got past infinity errors already but keep coming across more. Here's my code:

odbcCommand1.CommandType = CommandType.Text;
odbcCommand1.CommandText =
"INSERT INTO Churches (Name, Address1, Address2, Address3, PostCode) "+
"VALUES(textBox1.Text(?),textBox2.Text(?),textBox3.Text(?),textBox4.Text(?),textBox5.Text(?))";

odbcCommand1.Parameters.Add("@Name",
OdbcType.Text);
odbcCommand1.Parameters.Add("@Address1",
OdbcType.Text);
odbcCommand1.Parameters.Add("@Address2",
OdbcType.Text);
odbcCommand1.Parameters.Add("@Address3",
OdbcType.Text);
odbcCommand1.Parameters.Add("@PostCode",
OdbcType.Text);
try
{
odbcConnection2.Open();
odbcCommand1.ExecuteNonQuery();
}
catch (Exception e1)
{
MessageBox.Show(e1.ToString());
}
odbcConnection2.Close();

There could well be a blatent error there but as i'm new i can't see it! The error refers to an invalid buffer/string length... I've set them and un-set them and neither works. Do i need this much code to insert a record from values in textBoxes?

Any help would be appreciated! Thanx guys


Answers (1)