Author: dst101 | Posted on: 8/30/2010 6:40:17 AM | Views : 301

I need to carry the newly created value to another page using the ExecuteScalar method, I'm using the try catch finally but I'm a bit stuck with it, any help would be gratefully appreciated.
string connectionString = ConfigurationManager.ConnectionStrings["ViewpointDBConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
string strQuery = "INSERT INTO tbl_test(Demo) VALUES (@Demo)" +
"SELECT scope_identity();";
SqlCommand comm = new SqlCommand(strQuery, conn);

try{

comm.Parameters.Add("@Demo", SqlDbType.VarChar).Value = TBdemo.Text.ToString();conn.open();
string ID = comm.ExecuteScalar().ToString();

}

catch(Exception ex)
{
lblStatus.Text = ex.Message;
}
finally
{
Go to the complete details ...