Hello,
I have delete function and it doesn't function. I got this error:
"Missing semicolon (;) at end of SQL statement." even though I have a semicolon sign at the end of that statement.
Here is my code:
try
{
OleDbCommand commandbrisi = new OleDbCommand();
commandbrisi.CommandText = "Delete from Kazneti where Imeprezime = ? and Adresa = ? order by Rbr asc";
commandbrisi.Parameters.AddWithValue("@imeprez", txtImePrez.Text);
commandbrisi.Parameters.AddWithValue("@adresa", txtAdresa.Text);
commandbrisi.Connection = conn;
conn.Open();
OleDbDataAdapter oleDBDataAdapter1 = new OleDbDataAdapter(new OleDbCommand("Update * from Kazneti", conn));
commandbrisi.ExecuteNonQuery();//here is the error
_dataset.Clear();
oleDBDataAdapter1.Fill(_dataset, "Kazneti");
}
finally
{
conn.Close();
}
Loading
VulpesPosted Oct 19, 2011, 4:46 AM
I suspect the problem is in this line:
commandbrisi.CommandText = "Delete from Kazneti where Imeprezime = ? and Adresa = ? order by Rbr asc";
where you don't want the order by clause at the end of the Delete statement:
commandbrisi.CommandText = "Delete from Kazneti where Imeprezime = ? and Adresa = ?";
NelPosted Oct 19, 2011, 6:16 AM
NelPosted Oct 19, 2011, 6:15 AM
Satyapriya NayakPosted Oct 19, 2011, 6:06 AM
Try like this .....
OleDbConnection con=new OleDbConnection("connection string");
OleDbCommand com;
OleDBDataAdapter sqlda;
string str;
private void btndelete_Click(object sender, System.EventArgs e)
{
str = "delete from student where sid=@sid";
com = new OleDbCommand(str, con);
com.Parameters.Add("@sid", txtid.Text);
con.Open();
com.ExecuteNonQuery();
MessageBox.Show("Records Successfuly Deleted");
con.Close();
}
private void btnupdate_Click(object sender, System.EventArgs e)
{
con.Open();
str = "update student set sname=@sname,smarks=@smarks,saddress=@saddress,year=@year where sid=@sid";
com = new OleDbCommand(str, con);
com.Parameters.Add("@sid", txtid.Text);
com.Parameters.Add("@sname", txtname.Text);
com.Parameters.Add("@smarks", txtmarks.Text);
com.Parameters.Add("@saddress", txtaddress.Text);
com.Parameters.Add("@year", txtyear.Text);
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("Records Successfuly Updated");
}
Thanks
If this post helps you mark it as answer
Prabhu RajaPosted Oct 19, 2011, 5:59 AM
try this one.
commandbrisi.CommandText = "Delete from Kazneti where Imeprezime = @imeprez and Adresa = @adresa";
commandbrisi.Parameters["@imeprez"].Value = txtImePrez.Text;
commandbrisi.Parameters["@adresa"].Value = txtAdresa.Text;
Dhaval PatelPosted Oct 19, 2011, 4:50 AM
you have to change query update * from Kazneti to select * from Kazneti in this line
OleDbDataAdapter oleDBDataAdapter1 = new OleDbDataAdapter(new OleDbCommand("Update * from Kazneti", conn));