Skip to content

What is syntax error for the insert into qyery!! in c#

santhosh s samaka

Asked Jul 30, 2010, 9:59 PM EDT4 answers
Share
LinkedInX
 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();

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Hirendra Sisodiya
    0
    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();
     
    No need to write these Line (Red).
    thanks
     
    Please mark as answer if it helps
    0
  • 0
    i already tried that one that is not working and made changes like this
    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();
    0
  • 0
    it gives error in a error wind the error is Unhandled exception has occured in your appliction Syntax error in INSERT INTO Statement
    0
  • 1 short reply
    • Hirendra Sisodiya
      0
      what is the error??
       
      0