Results 1 to 2 of 2

Thread: Identity

  1. #1
    Join Date
    Dec 1969

    Default Identity

    I am trying to return and display the identity of a record that was written to the database. I have SELECT @@identity in the SQL stored proc. I am not familiar enough with ASP.NET to know the code for this: Here is my code so far...Can anyone help?<BR><BR>************************************* ***************************<BR>Dim myConnection as New SqlConnection(ConfigurationSettings.AppSettings("c onnString"))<BR><BR>Const strSQL as String = "UpdateCustomer"<BR>Dim myCommand as New SqlCommand(strSQL, myConnection)<BR><BR>myCommand.CommandType = CommandType.StoredProcedure<BR><BR>&#039;Set this to 0 so to write a new record<BR>Dim CustomerID As New SqlParameter("@IDCustomer", SqlDbType.Int, 4)<BR> CustomerID.Value = 0<BR> myCommand.Parameters.Add(CustomerID)<BR> <BR>Dim FName As New SqlParameter("@FName", SqlDbType.VarChar, 50)<BR> FName.Value = Session("T" & i & "FName")<BR> myCommand.Parameters.Add(FName)<BR> <BR>Dim LName As New SqlParameter("@LName", SqlDbType.VarChar, 50)<BR> LName.Value = Session("T" & i & "LName")<BR> myCommand.Parameters.Add(LName)<BR> <BR>Dim Email As New SqlParameter("@Email", SqlDbType.VarChar, 50)<BR> Email.Value = Session("T" & i & "Email")<BR> myCommand.Parameters.Add(Email)<BR><BR>myConnectio n.Open()<BR>myCommand.ExecuteNonQuery()<BR>******* ************************************************** *******

  2. #2
    Join Date
    Dec 1969

    Default RE: Identity

    If your proc is returning it as a resultset, you&#039;re going to have to call it with an ExecuteScaler() or ExecuteReader()instead of ExecuteNonQuery(). (ExecuteScaler() would be lower overhead, and therefore preferable.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts