Int64 id, ctele;
id = Convert.ToInt64(lbl_add_Id.Text);
string cname, caddress, cpost;
cname = txt_Add_Name.Text;
caddress = txt_Add_Address.Text;
cpost = txt_Add_PC.Text;
ctele = Convert.ToInt64(txt_Add_Tele.Text);
//SQL adapter to gain access to the database, including the SQL statement
OleDbDataAdapter da_Customer_View = new OleDbDataAdapter(
"INSERT INTO tbl_Customers" +
"VALUES('" + (id) + "'" + ",'" + (cname) + "','" + (caddress) + "','" + (cpost) + "','" + (ctele) + "')",
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Documents and Settings\\Me\\My Documents\\"
+ "SQL Databases\\XMAS SQL Database\\FoodTastic.accdb");
lst_New_Customers.Items.Clear();
UpdateCustomer();
Any idas?
[.net] C# SQL Insert Command.. Not working?
Hi, I'm quite new and have been looking for good advice! Lucky you.
Anywayss, I'm writing a program which has to INSERT data into my Access database.
Simple, atleast it should be. Having trouble though, its not actually doing it.
Can't figure it out either, I assume it mys SQL statement. I don't know how else I'd write it at least. Permissions may be an issue, I'm not sure.
Heres the code:
First problem I see is:
Without the +, this works out to:
"INSERT INTO tbl_CustomersVALUES('id' ..."
I'd suggest you use string.Format() to build your strings like these, so you can just do:
It'll make problems like this a lot easier to find.
"INSERT INTO tbl_Customers" + "VALUES('" + (id) + "'" ...
Without the +, this works out to:
"INSERT INTO tbl_CustomersVALUES('id' ..."
I'd suggest you use string.Format() to build your strings like these, so you can just do:
string s = string.Format("INSERT INTO {0} VALUES ('{1}','{2}','{3}' ...")...
It'll make problems like this a lot easier to find.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement