Last post Aug 10, 2011 11:28 PM by SANJISH KUMAR
Aug 08, 2011 12:03 AM|SANJISH KUMAR|LINK
I am developing a ENQUIRY MANAGEMENT SYSTEM for one of the Computer training institutes. Whenever the user presses the 'ADD' button the last enquiry number + 1 should be displayed in the enquiry no textbox. This is OK for a single user system but on
the net since multiple users could open the database at the same time , should I generate the enquiry no at the time of saving ? Also do i have to lock the database at the time of saving or is this done automatically by ado.net ? My code for the 'ADD' button
press is as under
If cn.State = 1
"Provider=Microsoft.Jet.OLEDB.4.0; Persist Security Info=False;Data Source = "
& Server.MapPath("~/APP_DATA/AS.MDB") &
"; User Id=Admin; Jet OLEDB:Database Password = virgos ;"
' enquiry no
"select * from ENQUIRYDESCSQL"
New OleDbCommand(strsql, cn)
objReader = objCmd1.ExecuteReader
cnt = 1
If objReader.HasRows =
cnt = objReader("enquiry_no") + 1
textboxEnqno = cnt
Another problem is that I have to open and close the connection everytime I have to do any processing on the database . Should I use datasets instead and open the connection only once ?
Thanks & regards
Aug 08, 2011 03:45 AM|yashwanthb|LINK
Yes its better to generate the enquiry no at the time of saving based on the existing no in database.
Aug 10, 2011 09:51 PM|Decker Dong - MSFT|LINK
For multiple users' using，I'd like to recommand you to save the record in the DataTable, and then use OleDbCommandBuilder to automatically generate the Update method so you can update it soon without considering too much about that...
Sinppet of codes are:
using (OleDbDataAdapter adapter = new OleDbDataAdapter("select * from xxx where ColumnName = your value",
new OleDbConnection("Your connection string here")))
DataTable dt = new DataTable();
OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter);
dt.Rows["ColumnName"] = "Your new value here";
dt.Rows.SetModified(); //to set it modified to avoid concurrency
Aug 10, 2011 11:28 PM|SANJISH KUMAR|LINK
Thanks DECKER for the solution