ASP -> Database (Insert)

Discussion in 'ASP General' started by Davy Marichael, Mar 29, 2005.

  1. Hi,

    i'm having problems with the insert command in .NET
    The Select statement works perfectly, but insert.. He gives an error when he
    executes the command:
    ExecuteNonQuery()

    Check the code below..
    Thanx in advance!

    Public Sub voegToe(ByVal aproduct As Product)

    Dim oConn As New OleDbConnection(mStrConn)

    Dim sqlCmd As String = "INSERT INTO Product (ProductName, Color, Sizes, M_F,
    Price, ProductTypeID, ProductClassID, UnitsInStock) VALUES (@ProductName,
    @Color, @Sizes, @M_F, @Price, @ProductTypeID, @ProductClassID,
    @UnitsInStock)"

    Dim oCmd As New OleDbCommand(sqlCmd, oConn)

    oCmd.Parameters.Add(New OleDbParameter("@ProductName", aproduct.Naam))

    oCmd.Parameters.Add(New OleDbParameter("@Color", aproduct.Kleur))

    oCmd.Parameters.Add(New OleDbParameter("@Sizes", aproduct.Maat))

    oCmd.Parameters.Add(New OleDbParameter("@M_F", aproduct.M_F))

    oCmd.Parameters.Add(New OleDbParameter("@Price", aproduct.Prijs))

    oCmd.Parameters.Add(New OleDbParameter("@ProductTypeID", aproduct.TypeID))

    oCmd.Parameters.Add(New OleDbParameter("@ProductClass", aproduct.ClassID))

    oCmd.Parameters.Add(New OleDbParameter("@UnitsInStock", aproduct.Voorraad))

    Try

    oConn.Open()

    oCmd.ExecuteNonQuery()

    oConn.Close()

    Catch ex As Exception

    Throw New Exception("Database niet gevonden")

    oConn.Close()

    End Try

    End Sub





    My DB is added in the config file so i don't know what the problem COULD
    be..

    I have the same problem with UPDATE & DELETE... Only SELECT works..
    Davy Marichael, Mar 29, 2005
    #1
    1. Advertising

  2. Davy Marichael wrote:
    > Hi,
    >
    > i'm having problems with the insert command in .NET



    There was no way for you to know it, but this is a classic asp newsgroup.
    While you may be lucky enough to find a dotnet-savvy person here who can
    answer your question, you can eliminate the luck factor by posting your
    question to a group where those dotnet-savvy people hang out. I suggest
    microsoft.public.dotnet.framework.aspnet.

    More below ...

    > The Select statement works perfectly, but insert.. He gives an error


    We're not psychic. What error?

    > when he executes the command:
    > ExecuteNonQuery()


    > Check the code below..
    > Thanx in advance!

    <snip>
    >
    >
    > My DB


    .... which you have not specified. The person helping you with this problem
    will need to know the type and version of the database you are using.

    > is added in the config file so i don't know what the problem
    > COULD be..
    >
    > I have the same problem with UPDATE & DELETE... Only SELECT works..


    You have not mentioned what the error was. Please try to describe your
    symptoms without using the words " doesn't work"

    Based on this last sentence, it looks like you are having a permissions
    problem. If it's an Access database (again, please do not make us guess),
    then you need to realize that all users of the database require read/write
    permissions for the folder containing the database file. This includes the
    aspnet user account under which your asp.net process is running.

    Bob Barrows


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows [MVP], Mar 29, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cannontrodder
    Replies:
    1
    Views:
    698
    cannontrodder
    Jul 25, 2006
  2. Replies:
    1
    Views:
    431
  3. Replies:
    1
    Views:
    1,758
    Albert Hopkins
    Dec 6, 2008
  4. eagle

    Insert & Insert/Repeat buttons in a detailsview

    eagle, Jul 12, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    1,028
    eagle
    Jul 12, 2007
  5. Feege
    Replies:
    0
    Views:
    419
    Feege
    Dec 20, 2005
Loading...

Share This Page