Results 1 to 5 of 5

Thread: [02/03] stored proc problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    29

    [02/03] stored proc problem

    I have a vb program that adds data into an Access Database. The query for this add works perfectly, but for some reason I can't get it to link to my program correctly. My break is comming on the ".executenonquery()", which leads me to believe its a query problem, but I don't see how thats possible if it works in Access...Here is the code, thanks for any help.
    Code in my module that i call
    VB Code:
    1. Public Sub AddMember(ByVal storedProc As String)
    2.         Dim spName As String
    3.         Dim cmd As New OleDbCommand
    4.  
    5.         odaMembers.SelectCommand = New OleDb.OleDbCommand
    6.         spName = storedProc
    7.         cnnAggieSatMembers.Open()
    8.  
    9.         With odaMembers.SelectCommand
    10.             .CommandType = CommandType.StoredProcedure
    11.             .CommandText = spName
    12.  
    13.             .Parameters.Add("@spLastName", OleDbType.VarChar, 25).Value = frmMain.txtNewLastName.Text
    14.             .Parameters.Add("@spFirstName", OleDbType.VarChar, 25).Value = frmMain.txtNewFirstName.Text
    15.             .Parameters.Add("@spPhone", OleDbType.VarChar, 25).Value = frmMain.txtNewPhone.Text
    16.             .Parameters.Add("@spEmail", OleDbType.VarChar, 50).Value = frmMain.txtNewEmailAddress.Text
    17.             .Parameters.Add("@spClass", OleDbType.VarChar, 10).Value = frmMain.txtNewClass.Text
    18.             .Parameters.Add("@spexpectedgraduation", OleDbType.VarChar, 25).Value = frmMain.txtNewExpectedGraduation.Text
    19.             .Parameters.Add("@spMajor", OleDbType.VarChar, 25).Value = frmMain.txtNewMajor.Text
    20.  
    21.             .Connection = cnnAggieSatMembers
    22.             .ExecuteNonQuery()
    23.         End With
    24.         cnnAggieSatMembers.Close()
    25.     End Sub

    Code from my form
    VB Code:
    1. Private Sub btnNewMember_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewMember.Click
    2.         Dim spLastName As String
    3.         Dim spFirstName As String
    4.         Dim spPhoneNumber As String
    5.         Dim spEmail As String
    6.         Dim spClass As String
    7.         Dim spExpectedGraduation As String
    8.         Dim spMajor As String
    9.         Dim spName As String
    10.  
    11.         Call AddMember("spAddMember")
    12.         odaMembers.SelectCommand = New OleDb.OleDbCommand
    13.  
    14.         Try
    15.             cnnAggieSatMembers.Open()
    16.             spName = "spSearchAll"
    17.             dsMembers.Clear()
    18.  
    19.             With odaMembers.SelectCommand
    20.                 .CommandType = CommandType.StoredProcedure
    21.                 .CommandText = spName
    22.                 .Connection = cnnAggieSatMembers
    23.             End With
    24.  
    25.             odaMembers.Fill(dsMembers, "myTable890")
    26.             dgResults.DataSource = dsMembers.Tables("myTable890")
    27.  
    28.         Catch ex As Exception
    29.             MsgBox(ex.Message)
    30.         End Try
    31.         cnnAggieSatMembers.Close()
    32.         GRBNewMemberINFO.Visible = False
    33.  
    34.         txtNewLastName.Text = ""
    35.         txtNewFirstName.Text = ""
    36.         txtNewEmailAddress.Text = ""
    37.         txtNewPhone.Text = ""
    38.         txtNewClass.Text = ""
    39.         txtNewMajor.Text = ""
    40.         txtNewExpectedGraduation.Text = ""
    41.         btnSearchMember.Focus()
    42.  
    43.     End Sub

  2. #2
    Banned
    Join Date
    May 2006
    Posts
    161

    Re: [02/03] stored proc problem

    You will need to post the stored procedure, and the exact error message for us to help you.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    29

    Re: [02/03] stored proc problem

    The stored procedure (query in access) looks like this...

    PARAMETERS spLastName Text ( 255 ), spFirstName Text ( 255 ), spPhoneNumber Text ( 255 ), spEmail Text ( 255 ), spClass Text ( 255 ), spExpectedGraduation Text ( 255 ), spMajor Text ( 255 );
    INSERT INTO tblMembers ( LastName, FirstName, PhoneNumber, email, class, expectedgraduation, Major )
    VALUES ([spSearchLastName], [spFirstName], [spPhoneNumber], [spEmail], [spClass], [spexpectedgraduation], [spMajor]);

    There error I'm getting is the following, "An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll." It hits on the "executenonquery()" part of the code. Thanks for any help.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [02/03] stored proc problem

    Help me here..... when the heck did they add Stored Procs to Access? .....

    As far as I know Access does NOT SUPPORT stored procedures..... now.... it is possible to use PARAMETERIZED QUERIES..... but they have a different syntax....
    Code:
    NSERT INTO tblMembers ( LastName, FirstName, PhoneNumber, email, class, expectedgraduation, Major )
    VALUES (?, ?, ?, ?, ?, ?, ?);
    And your CommandType should be Text... not StoredProcedure.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    29

    Re: [02/03] stored proc problem

    Yeah thats what I meant tg. Access does not have SP's like Server SQL does, but I've used parameterized queries and adapted them to something similar to a stored procedure. Oh, and the commandtype works as storedprocedure with every other query that I've adapted to this format, so I'm not sure if thats the problem or not.

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