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]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to