OleDB INSERT command error

六眼飞鱼酱① 提交于 2019-12-05 03:24:32

You defined @Username and @Password parameters but you never used in your sql command.

How about?

cmd.CommandText = "INSERT INTO Accountstbl (Username, [Password]) VALUES (@Username, @Password)";
cmd.Parameters.AddWithValue("@Username", textBox1.Text);
cmd.Parameters.AddWithValue("@Password", textBox2.Text);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();

Also you should use Password in square brackets on your sql command like [Password] because it is a reserved keyword in MS Access.

If you don't this can cause an error like;

Incorrect syntax near the keyword "Password"

Try to change this way

 cmd.CommandText = "INSERT INTO Accountstbl (Username, Password) VALUES (@Username,@Password)";

A space is required in your insert statement:

ssword)" + "VALUES ('" 

for example in your statement you have concatenated without allowing for a space.

Should be:

ssword)" + " VALUES ('" 

For example.

You can have this :

cmd.CommandText = "INSERT INTO Accountstbl (Username, [Password]) VALUES (@Username,@Password)";
            cmd.Parameters.AddWithValue("@Username", textBox1.Text);
            cmd.Parameters.AddWithValue("@Password", textBox2.Text);

I hope this will work.

Cheer-up.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!