Hi,
Could anybody help me please and tell me what's wrong with my code? Here it is:
OleDbCommand command = new OleDbCommand();
command.Connection = conn;
command.CommandText = "Update Kazneti set Imeprezime=?, Adresa=?, Datumstar=? where Rbr=?";
command.Parameters.AddWithValue("@imeprez", txtImePrez.Text);
command.Parameters.AddWithValue("@adresa", txtAdresa.Text);
command.Parameters.AddWithValue("@datn", txtDatumnov.Text);
command.Parameters.AddWithValue("@rbr", comboBox1.SelectedValue);
try
{
conn.Open();
OleDbDataAdapter oleDBDataAdapter1 = new OleDbDataAdapter(new OleDbCommand("Select * from Kazneti order by Imeprezime asc", conn));
_dataset.Clear();
oleDBDataAdapter1.Fill(_dataset, "Kazneti");
command.ExecuteNonQuery();//I got en error "Data type mismatch in criteria expression." here
}
Thank you.
Loading
NelPosted Oct 20, 2011, 4:14 AM
Satyapriya NayakPosted Oct 20, 2011, 3:48 AM
Use
command.Parameters.AddWithValue("@rbr", comboBox1.SelectedItem);
instead of
command.Parameters.AddWithValue("@rbr", comboBox1.SelectedValue);
Thanks
Prabhu RajaPosted Oct 20, 2011, 3:31 AM
Try this one.
command.CommandText = "Update Kazneti set Imeprezime=@imeprez, Adresa=@adresa, Datumstar=@datn where Rbr=@rbr";
command.Parameters.AddWithValue("@imeprez", txtImePrez.Text);
command.Parameters.AddWithValue("@adresa", txtAdresa.Text);
command.Parameters.AddWithValue("@datn", txtDatumnov.Text);
command.Parameters.AddWithValue("@rbr", comboBox1.SelectedValue); // make sure it would be String or any other datatype
before condition check in where clause of Query. if any other data type , convert it from string to that datatype.
Hemant KumarPosted Oct 20, 2011, 3:17 AM
You need to give the DBType also.Please check this Example
You are close with the rest of your connection and such, but as you note, doing it with parameterized queries is safer from SQL-Injection.