Arindam, If you use SQL Server or Access, use the SELECT @@ IDENTITY command instead of max value. Max value is much more likely to lead to problems. If your user load is small, I wouldn't worry too much about concurrency problems using SELECT @@IDENTITY. Ideally if you have a ton of users creating new rows at once, look into using a stored procedure. ..Matias
________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Arindam Sent: Tuesday, April 19, 2005 7:42 AM To: [email protected] Subject: RE: [AspNetAnyQuestionIsOk] How to get the value of auto field of current inserted row Hi Matias & Carroll Both of you recommended to use ExecuteScalar and SELECT @@IDENTITY. But my requirement is after isertion i want to send back the identity value with my ref parameter. so in this situation how "ExecuteScalar and SELECT @@IDENTITY" can be implemented. Though in the following function I have solved the problem...but I am not happy with the solution, as Matias said a nice thing "If many insertion happen at the same time, then it may not give right result." I agree, he is right. So i was just thinking, "transaction Isolationlevel" or any "locking" techniques can be implemented when Insertion happening, will be good. but I am not very sure about how to Implement. If u guys can show me the idea ...will be nice. Please have a look at the following code. public bool AddHotelBookingInfo(Hashtable BookingInfo,ref string BookingConfrmNo) { ObjConn.OpenConnection (); try { string InsertQry="Insert into MyTable (col1,col2,col3,col4) values ('value1','value2','value3','value4')"; SqlCommand objCmd=new SqlCommand(InsertQry,ObjConn.mysqlconn); objCmd.ExecuteNonQuery(); string FetchConfNo="Select Max(ConfrmNo)as ConfrmNo from MyTable "; SqlCommand objCmdfetch=new SqlCommand(FetchConfNo,ObjConn.mysqlconn); SqlDataReader objReader=objCmdfetch.ExecuteReader(CommandBehavior.CloseConnection); objReader.Read(); if (objReader.HasRows) { BookingConfrmNo=objReader["ConfrmNo"].ToString(); } objReader.Close(); ObjConn.closeConnection(); return true; } catch { BookingConfrmNo="0"; ObjConn.closeConnection(); return false; } } Regards, Arindam Thanks & Regards Arindam Web Designer & Developer Yahoo! India Matrimony: Find your life partneronline. [Non-text portions of this message have been removed] ________________________________ Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/ * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> * Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service <http://docs.yahoo.com/info/terms/> . [Non-text portions of this message have been removed] Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
