Tim313
asked on
Insert Into Statement
I have a form with multiple txt and ck boxes, some filled by query, others by user.
How do I refer to these boxes in the "values" of a Insert Into statement?
How do I refer to these boxes in the "values" of a Insert Into statement?
looks ugly.. try this:
// note the usage of the single quotes;
string insertString = @"insert into tbl1 (Col1, Col2, Col3) values ('" + txtField1.Text + "', " + chkBox1.Checked + ", '" + txtField2.Text + "')";
// 1. Instantiate a new command with a query and connection
SqlCommand cmd = new SqlCommand(insertString, conn);
// 2. Call ExecuteNonQuery to send command
cmd.ExecuteNonQuery();
ASKER
nmarun,
Thank you for your reply.
I neglected to include that I'm using Visual Basic 2005 Express and MS Access 2003.
Can you help me again with the same question, based on the above?
Thank you for your reply.
I neglected to include that I'm using Visual Basic 2005 Express and MS Access 2003.
Can you help me again with the same question, based on the above?
Go throught this link for connecting to an MS Access database:
http://www.geekpedia.com/tutorial60_ADO-.NET-and-Access-database-I.html
http://www.geekpedia.com/tutorial60_ADO-.NET-and-Access-database-I.html
ASKER
nmarun,
Thanks for the link, but I have my connection set-up. Just need to know if the ' " + txtField.Text + " ' and the " + chkBox1.Checked + " references are still applicable with VB2005 & MS Access 2003.
Thanks for the link, but I have my connection set-up. Just need to know if the ' " + txtField.Text + " ' and the " + chkBox1.Checked + " references are still applicable with VB2005 & MS Access 2003.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks.
// note the usage of the single quotes;
string insertString = @"
insert into Categories
(Col1, Col2, Col3)
values ('" + txtField1.Text + "', " + chkBox1.Checked + ", '" + txtField2.Text + "')";
// 1. Instantiate a new command with a query and connection
SqlCommand cmd = new SqlCommand(insertString, conn);
// 2. Call ExecuteNonQuery to send command
cmd.ExecuteNonQuery();
For a better understanding please read:
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson01.aspx