Please, I spend a lot of time, and still cant figure out this simple task. I need to update a row in a table. Table (members) has following structure: id = int phone = varchar name = varchar
I have a method that takes values from a form. This is the method.
C#
publicvoiddoupdate(string phone, string name, int id)
{
SqlCeCommand DAUpdateCmd;
DataSet ds = new DataSet();
SqlCeConnection con = new SqlCeConnection(@"Data Source=C:\\users.sdf");
con.Open();
SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * from members ORDER BY id", con);
DAUpdateCmd = new SqlCeCommand("INSERT INTO members(phone, name) VALUES(@phone,@name) WHERE id = 'id', con");
da.UpdateCommand = DAUpdateCmd;
da.Fill(ds, "members");
da.Update(ds, "members");
con.Close();
After I call that method, nothing happens. No error and no update... This is driving me crazy.
I really tried lots of combination, and now I am totally brainless... everything is mixed in my head now.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
vedran16 reputationPosted Jun 9, 2010, 5:01 AM EDT
0
I have looked at many places, and added some code. But still nothing. Here is the now revised code.
C#
publicvoiddoupdate(string phone, string name, int id)
{
SqlCeCommand DAUpdateCmd;
DataSet ds = new DataSet();
SqlCeConnection con = new SqlCeConnection(@"Data Source=C:\\users.sdf");
con.Open();
SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * from members ORDER BY id", con);
DAUpdateCmd = new SqlCeCommand("INSERT INTO members(phone, name) VALUES(@phone,@name) WHERE id = 'id', con");
DAUpdateCmd.Parameters.Add("@phone", phone);
DAUpdateCmd.Parameters.Add("@name", name);
DAUpdateCmd.Parameters.Add("@id", id);
da.UpdateCommand = DAUpdateCmd;
When I execute that code, nothing happens. I set the BreakPoint in that method, and I see that my variables are moving along nicely, but there is no update... nothing.
vedran16 reputationPosted Jun 9, 2010, 5:01 AM EDT
public void doupdate(string phone, string name, int id) { SqlCeCommand DAUpdateCmd; DataSet ds = new DataSet(); SqlCeConnection con = new SqlCeConnection(@"Data Source=C:\\users.sdf"); con.Open(); SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * from members ORDER BY id", con); DAUpdateCmd = new SqlCeCommand("INSERT INTO members(phone, name) VALUES(@phone,@name) WHERE id = 'id', con"); DAUpdateCmd.Parameters.Add("@phone", phone); DAUpdateCmd.Parameters.Add("@name", name); DAUpdateCmd.Parameters.Add("@id", id); da.UpdateCommand = DAUpdateCmd;da.Fill(ds, "members");
da.Update(ds, "members");
con.Close();
When I execute that code, nothing happens. I set the BreakPoint in that method, and I see that my variables are moving along nicely, but there is no update... nothing.
Please help me here :)