Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get a syntax error when try to insert datas using following code can any help to solve this problem?

C#
con = new OleDbConnection(cs);
                con.Open();

                string cb = "insert into Users(UserID,UserName,UserType,Cluster,Password,Email) VALUES (@d1,@d2,@d3,@d4,@d5,@d6)";

                cmd = new OleDbCommand(cb);

                cmd.Connection = con;

                cmd.Parameters.Add(new OleDbParameter("@d1", OleDbType.Char, 30, "UserID"));

                cmd.Parameters.Add(new OleDbParameter("@d2", OleDbType.Char, 30, "UserName"));
                cmd.Parameters.Add(new OleDbParameter("@d3", OleDbType.Char, 10, "UserType"));

                cmd.Parameters.Add(new OleDbParameter("@d4", OleDbType.Char, 30, "Cluster"));
                cmd.Parameters.Add(new OleDbParameter("@d5", OleDbType.Char, 30, "Password"));


                cmd.Parameters.Add(new OleDbParameter("@d6", OleDbType.Char, 30, "Email"));


                cmd.Parameters["@d1"].Value = TxtUID.Text.Trim();
                cmd.Parameters["@d2"].Value = TxtUname.Text;
                cmd.Parameters["@d3"].Value = CmbUtype.Text;
                cmd.Parameters["@d4"].Value = CmbCluster.Text;
                cmd.Parameters["@d5"].Value = TxtPw.Text;
                cmd.Parameters["@d6"].Value = TxtEml.Text;
                cmd.ExecuteReader();




                con.Close();
                MessageBox.Show("Successfully Registered", "User", MessageBoxButtons.OK, MessageBoxIcon.Information);


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }
Posted
Comments
cvogt61457 27-Oct-13 14:17pm    
Can you be more specific on the error?
What line number?
What is the error text?
You haven't provided any detail and we can only guess.
Richard.Berry100 27-Oct-13 16:05pm    
Your command text is an INSERT statement, but you go cmd.ExecuteReader?
should it not be cmd.ExecuteNonQuery();

1 solution

Try debugging your source code. That should give you an idea on what the error is and where it occurs. This could help you track the root of the problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900