On 4/17/05, Arindam <[EMAIL PROTECTED]> wrote:
> I have a table with 4 columns,
> > First Column is auto-incremented numeric field,
> >
> > I want to get the value of that auto incremented field, when i insert a
> new
> > record.
> > because i need to send that number back to my funcation.
> >
> >
> > Pls look at the function bellow.
> >
> >
> >
> > public bool AddHotelBookingInfo(Hashtable BookingInfo,ref string
> > BookingConfrmNo)
> > {
> > ObjConn.OpenConnection ();
> > try
> > {
> > string InsertQry="Insert into Tab_BookingDtls
> (H_Name,H_Id,Guest_FName)
> > values";
> > InsertQry += " '"+
> >
> BookingInfo["h_Name"].ToString().Replace("'","''")+"','"+BookingInfo["h_Id"].ToString().Replace("'","''")+"','"+BookingInfo["g_FName"].ToString().Replace("'","''")+"'";
> > SqlCommand objCmd=new SqlCommand(InsertQry,ObjConn.mysqlconn);
> > objCmd.ExecuteNonQuery();
1. add a
";select @@identity" to your SQL
2. use ExecuteScalar which grabs that value rather than ExecuteNonQuery
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/