string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Samples\\login.mdb";
String uname, pass;
uname = textBox1.Text;
pass = textBox2.Text;
OleDbConnection myConnection = new OleDbConnection(connectionString);
myConnection.Open();
String query = "insert into LOGIN_TABLE (UserName, Password) VALUES ('" + textBox1.Text.ToString() + "','" + textBox2.Text.ToString() + "') ";
OleDbCommand myCommand = new OleDbCommand(query, myConnection);
//myCommand.CommandText = query;
OleDbParameter myParm = myCommand.Parameters.Add("@uname", OleDbType.VarChar, 50);
myParm.Value = textBox1.Text;
myParm = myCommand.Parameters.Add("@pass", OleDbType.VarChar, 50);
myParm.Value = textBox2.Text;
myCommand.ExecuteNonQuery();
myConnection.Close();
What is syntax error for the insert into qyery!! in c#
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Hirendra SisodiyaRank #256 · 9.8K pointsPosted Jul 30, 2010, 10:25 PM EDT
String uname, pass;
uname = textBox1.Text;
pass = textBox2.Text;
OleDbConnection myConnection = new OleDbConnection(connectionString);
myConnection.Open();
String query = "insert into LOGIN_TABLE (UserName, Password) VALUES ('" + textBox1.Text.ToString() + "','" + textBox2.Text.ToString() + "') ";
OleDbCommand myCommand = new OleDbCommand(query, myConnection);
//myCommand.CommandText = query;
// OleDbParameter myParm = myCommand.Parameters.Add("@uname", OleDbType.VarChar, 50);
// myParm.Value = textBox1.Text;
// myParm = myCommand.Parameters.Add("@pass", OleDbType.VarChar, 50);
// myParm.Value = textBox2.Text;
myCommand.ExecuteNonQuery();
myConnection.Close();
No need to write these Line (Red).
thanks
Please mark as answer if it helps
santhosh s samaka4 pointsPosted Jul 30, 2010, 10:31 PM EDT
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Samples\\login.mdb";
String uname, pass;
uname = textBox1.Text;
pass = textBox2.Text;
OleDbConnection myConnection = new OleDbConnection(connectionString);
myConnection.Open();
String query = "insert into LOGIN_TABLE (UserName, Password) VALUES (?, ?)";
OleDbCommand myCommand = new OleDbCommand(query, myConnection);
//myCommand.CommandText = query;
OleDbParameter myParm = myCommand.Parameters.Add("@uname", OleDbType.VarChar, 50);
myParm.Value = textBox1.Text;
myParm = myCommand.Parameters.Add("@pass", OleDbType.VarChar, 50);
myParm.Value = textBox2.Text;
myCommand.ExecuteNonQuery();
myConnection.Close();
santhosh s samaka4 pointsPosted Jul 30, 2010, 11:51 PM EDT
1 short reply
Hirendra SisodiyaRank #256 · 9.8K pointsPosted Jul 30, 2010, 11:10 PM EDT