Hi guys!
I done a project in c#... problem is in command parameter. my database is in access and all fields datatype is text.
my code is...
var dialogResult = MessageBox.Show("Are You want to Submit","Question",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
if (dialogResult == DialogResult.OK)
{
cmd = new OdbcCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update brdans set ques='"+Ques_txt.Text+"',ans=@Ans where s_roll='" + Roll + "'";
cmd.Parameters.AddWithValue("@Ans", ans_txt.Text);
cmd.ExecuteNonQuery();
con.Close();
}
my error comes with message...
ERROR [07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
thanks in advance
Upendra Pratap ShahiPosted Jun 18, 2015, 5:51 AM
Khan Abrar AhmedPosted Jun 18, 2015, 5:35 AM
if (dialogResult == DialogResult.OK)
{
cmd = new OdbcCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update brdans set [ques]='"+Ques_txt.Text+"',[ans]=@Ans where [s_roll]='" + Roll + "'";
cmd.Parameters.AddWithValue("@Ans", ans_txt.Text);
cmd.ExecuteNonQuery();
con.Close();
}
if not then try this on
if (dialogResult == DialogResult.OK)
{
cmd = new OdbcCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update brdans set [ques]='"+Ques_txt.Text+"',[ans]=@Ans where [s_roll]=?'" + Roll + "'";
cmd.Parameters.AddWithValue("@Ans", ans_txt.Text);
cmd.ExecuteNonQuery();
con.Close();
}