Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Database > MS Access

MS Access Related discussions using Access and JET as the backend

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-26-2009, 12:22 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jun 2009
Location: Mandurah
Age: 21
Posts: 2
Reputation: 0
Bendude is on a distinguished programming path ahead
Default Execute Access Query From VB.NET App

Hello everyone, its my first post here.

What i am trying to achieve is to execute queries i have already created which are stored in my access file from my VB application.

My code looks like this.

Code:
'Dim command As OdbcCommand = New OdbcCommand
    Using cnx As New OdbcConnection(My.Settings.connectionString)
        Using command As New OdbcCommand
            command.Connection = cnx
            command.CommandText = "sp_InsertClient"
            command.CommandType = CommandType.StoredProcedure



            '//====== create ABN paramenter =============
            Dim param1 As OdbcParameter = New OdbcParameter("inABN", abn)
            param1.Direction = ParameterDirection.Input
            param1.DbType = DbType.String
            'add abn parameter
            command.Parameters.Add(param1)

            '//====== create CompanyName Parameter ================
            Dim param2 As OdbcParameter = New OdbcParameter("inCompanyName", companyName)
            param2.Direction = ParameterDirection.Input
            param2.DbType = DbType.String
            'add the parameter
            command.Parameters.Add(param2)

            '//======== create ContactName Param ===============
            Dim param3 As OdbcParameter = New OdbcParameter("inContactName", contactName)
            param3.Direction = ParameterDirection.Input
            param3.DbType = DbType.String
            'add the parameter
            command.Parameters.Add(param3)

            '//=========== create PhoneNumber Parameter ===============
            Dim param4 As OdbcParameter = New OdbcParameter("inPhoneNumber", phoneNumber)
            param4.Direction = ParameterDirection.Input
            param4.DbType = DbType.String
            'add paramater
            command.Parameters.Add(param4)

            '//=========== create Address Parameter ===============
            Dim param5 As OdbcParameter = New OdbcParameter("inAddress", address)
            param5.Direction = ParameterDirection.Input
            param5.DbType = DbType.String
            'add paramater
            command.Parameters.Add(param5)

            Try
                cnx.Open()
                command.ExecuteNonQuery()
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Error", _
                                MessageBoxButtons.OK, MessageBoxIcon.Error)

                Exit Sub

            End Try

        End Using

    End Using
    MessageBox.Show("DONE")

End Sub
and the query sp_InsertClient looks like

Code:
INSERT INTO tblClients ( ABN, CompanyName, ContactName, PhoneNumber, Address )

VALUES ([inABN], [inCompanyName], [inContactName], [inPhoneNumber], [inAddress]);
I have browsed the net far and wide but still i can not get it to work... The error i am recieving is

nvalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.

Thanks if anyone can help
Ben
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
access, vb.net 2008


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 12:19 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.