ASP.NET programmers can you help me with this code please?

Discussion in 'Digital Media' started by ~*Ashley Star*~, Mar 20, 2008.

  1. SqlConnection objConnect = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["RequestTrackConnectionString"].ConnectionString);

    SqlCommand cmd = new SqlCommand("InsertRequest", objConnect);cmd.CommandType = CommandType.StoredProcedure;

    SqlParameter spRequestKey = new SqlParameter("@RequestKey", SqlDbType.BigInt, 4);
    spRequestKey.Value = ParameterDirection.ReturnValue;

    SqlParameter spEntryDate = new SqlParameter("@EntryDate", SqlDbType.DateTime);
    spEntryDate.Value = DateTime.Today;

    SqlParameter spSummary = new SqlParameter("@Summary", SqlDbType.NVarChar, 1000);
    spSummary.Value = txtRequest.Text;

    SqlParameter spRequestStatusCodeKey = new SqlParameter("@RequestStatusCodeKey", SqlDbType.BigInt, 4);
    spRequestStatusCodeKey.Value = ParameterDirection.ReturnValue;

    SqlParameter spEntryUserID = new SqlParameter("@EntryUserID", SqlDbType.NVarChar, 50);
    spEntryUserID.Value = txtUserID.Text;
    SqlParameter spEntryAffiliateKey = new SqlParameter("@EntryAffiliateKey", SqlDbType.BigInt, 4);
    spEntryAffiliateKey.Value = ParameterDirection.ReturnValue;

    SqlParameter spEntryPracticeKey = new SqlParameter("@EntryPracticeKey", SqlDbType.BigInt, 4);
    spEntryPracticeKey.Value = ParameterDirection.ReturnValue;

    SqlParameter spEntryUserEmail = new SqlParameter("@EntryUserEmail", SqlDbType.NVarChar, 200);
    spEntryUserEmail.Value = txtEmailAddress.Text;

    cmd.Parameters.Add(spRequestKey);
    cmd.Parameters.Add(spEntryDate);
    cmd.Parameters.Add(spSummary);
    cmd.Parameters.Add(spRequestStatusCodeKey);
    cmd.Parameters.Add(spEntryUserID);
    cmd.Parameters.Add(spEntryAffiliateKey);
    cmd.Parameters.Add(spEntryPracticeKey);
    cmd.Parameters.Add(spEntryUserEmail);

    objConnect.Open();
    cmd.ExecuteNonQuery();
    objConnect.Close();
    cmd.ExecuteNonQuery();

    Giving me an issue "Cannot insert explicit value for identity column in table 'Request' when IDENTITY_INSERT is set to OFF."

    Yes the PK in the request table is an autofill...how would I change the code above 0-0 This happens everytime I try to hit the submit form button after putting information in the text boxes
    ******************
    I just tried commenting out everything dealing w/ @Request but it says

    "Procedure 'InsertRequest' expects parameter '@RequestKey', which was not supplied."

    ~~InsertRequest is the name of my stored procedure BTW
    Does the statement

    SqlParameter spRequestKey = new SqlParameter("@RequestKey", SqlDbType.BigInt, 4);
    spRequestKey.Value = ParameterDirection.ReturnValue;

    tryin to insert a value then? Hmm :/ not sure not sure
  2. Roshan Guest

    Roshan
    Exactly what help do you need?

    Go to this website
    http://www.experts-exchange.com

    Here people answer technical queries, make sure you post your question in right forum!
  3. Aardvark Guest

    Aardvark
    Sounds to me like the problem is with the Stored Procedure, not your ASP.NET code.

    My guess is that when "InsertRequest" does its insert, it tries to place a value into a column that is auto-incremented, and that is not something you are allowed to do.
Loading...

Share This Page