Link to home
Start Free TrialLog in
Avatar of fwipho
fwipho

asked on

Update foxpro dbf from c# problem (Syntax Error)

I am having problems updating a foxpro table from c#  

The code I am using is :   Any ideas on what is happening . Currently I am getting Syntax error as exception.

Do I have to do the update command slightly different when updating a foxpro table!

                 // Read all required data
                    damodreg = new OleDbDataAdapter("Select field, mrindex from modreg ", MyConn);

                    //OleDbCommandBuilder MyCommand = new OleDbCommandBuilder(damodreg);
                    damodreg.Fill(dtModreg);

                    String UpdateCmd = "Update modreg set field= @field where index = @index";
                    OleDbCommand cmdupdate = new OleDbCommand(UpdateCmd, MyConn);
                    cmdupdate.Parameters.Add("@field", OleDbType.VarChar, 20,"field");

                    OleDbParameter Prm = cmdupdate.Parameters.Add("@index", OleDbType.Integer,5,"index");
                    Prm.SourceVersion = DataRowVersion.Original;
                    damodreg.UpdateCommand = cmdupdate;



                          dtModreg.Rows[i_idx +1 ]["field"] = "updated";
                           damodreg.Update(dtModreg);
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

if the field is called mrindex (as in the query), should the update not use that name? (just a guess)

                    String UpdateCmd = "Update modreg set field= @field where mrindex = @index";
>OleDbParameter Prm = cmdupdate.Parameters.Add("@index", OleDbType.Integer,5,"index");

for integer data types, you don't need to specify the size, and the value of "index" if wrong for sure:
                    OleDbParameter Prm = cmdupdate.Parameters.Add("@index", OleDbType.Integer);
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial