Friday, May 11, 2007

Dataset on the server.... ugh

I wrote the following to send the ext.datastore to the server, in response to a 'save button' click.

Code:
var editedds = myextdatastore.getModifiedRecords();

var ds4 = new Ajax.Web.DataSet();
var dt4 = new Ajax.Web.DataTable();

for(var i = 0, len = myextdatastore.fields.keys.length; i < i =" 0," len =" editedds.length;">


My C# routine correctly reads the dataset on the server but I'm disappointed that now I have to create all the insert/update/delete logic by creating 'insertcommand','updatecommand' etc. I thought the whole point of using ADO datasets was that it would handle all this logic. It seems like there is no way to get around having to code this on the server.

Below is my c# code. It returns no errors but it doesn't update either.....

Code:public static String SaveAll(System.Data.DataSet ds )
{
OleDbDataAdapter oda = getAccessAdapter();

OleDbCommandBuilder bld = new OleDbCommandBuilder(oda);
bld.GetInsertCommand(true);
OleDbCommand command;

command = new OleDbCommand(
"INSERT INTO TblOperations (Device,Operation) " +
"VALUES ( ?,?)");

command.Parameters.Add("@Device", OleDbType.VarChar, 40, "Device");
command.Parameters.Add("@Operation", OleDbType.VarChar, 40, "Operation");

oda.InsertCommand = command;

command = new OleDbCommand("UPDATE TblOperations SET Device=?, Operation=? WHERE ID_key=?");
command.Parameters.Add(new OleDbParameter("Device", OleDbType.VarChar , 50));
command.Parameters.Add(new OleDbParameter("Operation", OleDbType.VarChar, 50));
command.Parameters.Add(new OleDbParameter("ID_key", OleDbType.Numeric, 0));

oda.UpdateCommand=command;

oda.Update(ds, "Table1");

return " hello world " + oda.UpdateCommand.CommandText;

}

No comments: