Friday, May 11, 2007

dataset on the server....grow your own sql

I have spent some time trying to get the Ext datastore translated to a .Net dataset for updating but I've come to the conclusion that its just not worth the effort. I've heard others say that its not worth working with datasets except for simple out of the box applications and now I believe that too.

The dataset that gets sent to the server side routine needs to have its row's 'setmodified' or 'setadded' method set and then the dataset needs to be 'merged'. Then, it is just a black box in terms of what happens and it is difficult to get the underlying SQL when there are problems. I have done the following on the server side for the updates. I have a handler for the Ext data store 'update' event so that every field change on the grid will cause this code to fire. I added a timestamp column to the table to handle optimistic concurrency.

Code:

conn = new OleDbConnection(ads.ConnectionString);
conn.Open();

foreach (DataRow row in ds.Tables[0].Rows) // should always be one row
{

sqlcmd = "UPDATE TblOperations SET ";
sqlcmd += " Device = '" + row["Device"].ToString() + "', ";
sqlcmd += " Station = '" + row["Station"].ToString() + "' ";
sqlcmd += " where ID_key = " + row["ID_key"].ToString();
if (! row["timest"].ToString().Equals("") )
sqlcmd += " and timest = '" + row["timest"].ToString() + "' ";

cmd = new OleDbCommand(sqlcmd, conn);
affected += cmd.ExecuteNonQuery();
}

if ( affected == 1 )
return "";
else
return "error"



Now I need to get 'adds' and 'deletes' handled.

No comments: