CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2003
    Posts
    2

    Running Stored Procedure in VB.Net but not working

    I created a stored procedure during the development of the vb.net windows application.
    When I run the program, there's no error. But when I check in sqlserver7.0, the data is not inserted. I've already made sure that in the SQL Enterprise Manager, Permission, the Exec box is checked. Below is the code which I wrote:

    Dim CreditCard_ACFConn As New SqlConnection("workstation id=""MyServer"";packet size=4096;user id=sa;data source=""MyServer"";persist security info=False;initial catalog=CreditCard_ACF")

    Dim InsertCHCmd2 As New SqlCommand("spInsertCardHolderNonAgent", CreditCard_ACFConn)
    InsertCHCmd2.CommandType = CommandType.StoredProcedure
    Dim parmCHName2 As New SqlParameter("@CardHolderName", SqlDbType.VarChar, 255)
    parmCHName2.Value = txtCHName.Text
    InsertCHCmd2.Parameters.Add(parmCHName2)
    CreditCard_ACFConn.Open()
    InsertCHCmd2.ExecuteNonQuery()
    CreditCard_ACFConn.Close()

    If I replace the Stored Procedure name with SQL command, the same code can run perfectly!

    Dim CreditCard_ACFConn As New SqlConnection("workstation id=""MyServer"";packet size=4096;user id=sa;data source=""MyServer"";persist security info=False;initial catalog=CreditCard_ACF")

    Dim InsertCHCmd2 As New SqlCommand("Insert into CardHolder (CardHolderName) Values (@CardHolderName)", CreditCard_ACFConn)
    InsertCHCmd2.CommandType = CommandType.Text
    Dim parmCHName2 As SqlParameter = InsertCHCmd2.Parameters.Add("@CardHolderName", SqlDbType.VarChar, 255)
    parmCHName2.Value = txtCHName.Text
    CreditCard_ACFConn.Open()
    InsertCHCmd2.ExecuteNonQuery()
    CreditCard_ACFConn.Close()

    Please help. thanks

  2. #2
    Join Date
    Aug 2003
    Location
    U.A.E
    Posts
    3
    hi,

    the problem is from your stored procedure so try to use different datatype because some time its effect the data


    also check your code that your are correctly executing the coomand itself


    and tell me what will happen


    Ammar

  3. #3
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167
    When debugging stored procedure, the first thing to do is test your SP directly (via Query Analyzer or Enterprise Manager). Once you're assured that works, then you can start debugging your code.

    Use the step through feature (set a break point at the beggining of the routine that contains the code you mentioned above) and evaluate each input that you're passing to the stored procedure. Also, it does help to trap and display error(s) (TRY...CATCH...END TRY).

    Good Luck,
    -Cool Bizs

  4. #4
    Join Date
    Aug 2003
    Posts
    102

    source column

    Try placing a source column on the command parameter

    try this...................

    Dim parmCHName2 As New SqlParameter("@CardHolderName", SqlDbType.VarChar, 255,"CardHolderName")

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured