hi,
I know usung the wizards this is damn easy but i need to do this from code:
I have written this code in my DAL to retrreive A record by user name... i need to re-write the code to handle optimistic concurrecny.... could any one give me few pointer or modification to my code:
public DataSet GetRecord(string userName) { da.SelectCommand = cmdSelect; da.SelectCommand.Parameters.Clear(); ds.Tables.Clear(); da.SelectCommand.CommandType = CommandType.StoredProcedure; da.SelectCommand.CommandText = "ProcGetUsers"; da.SelectCommand.Connection = con; da.SelectCommand.Parameters.Add("@PUserName", SqlDbType.NVarChar, 50, "UserName"); da.SelectCommand.Parameters["@PUserName"].Value = userName; da.SelectCommand.Parameters.Add("@PFirstName", SqlDbType.NVarChar, 50, "FirstName"); da.SelectCommand.Parameters["@PFirstName"].Direction = ParameterDirection.Output; da.SelectCommand.Parameters.Add("@PLastName", SqlDbType.NVarChar, 50, "LastName"); da.SelectCommand.Parameters["@PLastName"].Direction = ParameterDirection.Output; da.SelectCommand.Parameters.Add("@PUpdatedTime", SqlDbType.DateTime, -1, "UpdatedTime"); da.SelectCommand.Parameters["@PUpdatedTime"].Direction = ParameterDirection.Output; da.SelectCommand.Connection.Open(); da.Fill(ds); da.SelectCommand.Connection.Close(); return ds; }
|
theLizardPosted Oct 31, 2009, 2:12 AM
Do you have an email address I can send you some code?
This is one function in the class I will send you, it executes queries - insert, update or delete to run stored procs you could send this function something like this - execSQL("EXECUTE(stored_proc_name)" );
//-----------------------------------------------------------------
public bool execSQL(string s)
{
bool success = true;
sqlCon con = new sqlCon();
try
{
con.connect();
con.command(s);
con.beginTrans();
con.write();
con.commitTrans();
}
catch (Exception err)
{
con.rollbackTrans();
success = false;
}
finally
{
con.terminate();
}
return (success);
}
//-----------------------------------------------------------------
other functions allow you to easily get fields from returned result set and populate text boxes etc.
functions like get("field_name") would be used like this TextBox1.text = con.get("CustomerName");
other syntax - to load combo boxes
while(con.read())
{
ComboBox1.Items.Add(con.get("CustomerName"));
}
Does this make sense.
petre ricardoPosted Nov 1, 2009, 6:16 AM
So i've used the contact user option to send my email address anyway...
But i have received a reply .... TY for the code :)
Petre
theLizardPosted Nov 1, 2009, 1:47 AM
petre ricardoPosted Oct 31, 2009, 11:25 PM
petre ricardoPosted Oct 30, 2009, 11:01 PM
Thanks for the reply...I have put my answers underneath your questions! :)
Q: Do you want this to be PURE code or are you using databound controls to do most of your work?
A: I need to do this primary in pure code, but i would also love to know how to do this by databounds...reasons for pure code most of the time my PM asks forpure code
Q: Is there a reason why you are using stored procedures for this task? Sometimes stored procedures take longer than straight queries.
A: PM insists on SP
Q: There are Ups and Downs for both, does your application really need stored procs?
A: Application doesnt but my PM does!
Q: Do you really need a DataSet or do you just want the user record in text boxes?
A: Would love to know both :)
Thank you!
theLizardPosted Oct 30, 2009, 5:22 PM
If you want this to be pure code then the preparation will be time consuming but when all things are in place, your work flow will be rapid and a little easier.
Is there a reason why you are using stored procedures for this task? Sometimes stored procedures take longer than straight queries.
There are Ups and Downs for both, does your application really need stored procs?
Do you really need a DataSet or do you just want the user record in text boxes?
If you are just reading data and not making changes then Optimistic or Pessamistic concurrency should not be of concern.
In pure code you would control all aspects of connecting, opening and updating records in your tables.