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

VulpesRank #55 · 29.2K reputationPosted Oct 19, 2011, 12:46 AM EDT
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 = ?";
Dhaval PatelRank #1,023 · 1.9K reputationPosted Oct 19, 2011, 12:50 AM EDT
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));
Prabhu RajaRank #861 · 2.6K reputationPosted Oct 19, 2011, 1:59 AM EDT
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;
Satyapriya NayakRank #47 · 31.5K reputationPosted Oct 19, 2011, 2:06 AM EDT
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
NelRank #2,060 · 702 reputationPosted Oct 19, 2011, 2:15 AM EDT
NelRank #2,060 · 702 reputationPosted Oct 19, 2011, 2:16 AM EDT