Need hel Updating DataGrid to data base on Pocket PC! (got Strange error)

M

MBadawi

I'm doing a task that is supposed to retrieve data from data base and
then displays it on a datagrid control, the user could modify the data
and then I try to update the data base with the modification.. I get
an SQLce exption " could not pars the query", knowing that this same
statement some times work!!

I cant find where is my error!! Here is a portion of the code which
the data base should be updated:

// This where the data base get updated
private void UpdatePB_Click(object sender, System.EventArgs e)
{
textEdit.Visible = false;
da.UpdateCommand = new SqlCeCommand("update plan_action_detail"
+" set pland_plan_visit = pland_plan_visit"
+" where phy_eng_name = @phy_eng_name"
+" and phy_speciality = @phy_speciality"
+" and pland_pot_code = @pland_pot_code", conn);
da.UpdateCommand.Parameters.Add("@pland_plan_visit",
SqlDbType.Decimal, 5, "pland_plan_visit");
da.UpdateCommand.Parameters.Add("@phy_eng_name", SqlDbType.NVarChar,
40, "phy_eng_name");
da.UpdateCommand.Parameters.Add("@phy_speciality",
SqlDbType.NVarChar, 5, "phy_speciality");
da.UpdateCommand.Parameters.Add("@pland_pot_code",
SqlDbType.NVarChar, 1, "pland_pot_code");

try
{
da.Update(DataGridDS.Tables[0]);
}
catch (SqlCeException exp)
{
MessageBox.Show(exp.Message);
}

}
 
G

Guest

H

Shouldnt your set statement b

"set pland_plan_visit = @pland_plan_visit

instead of "set pland_plan_visit = pland_plan_visit

Thank

Bal
 
A

Alex Feinman [MVP]

There is something wrong with the query as you posted it. In essence you
have:
Update a set b=b where ....
That would not update anything. Aside of that you should be using "?"
instead of named parameters.

cmd.CommandText = "update myTable set fld1 = ? where fld2 = ?"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top