ASP -> Database (Insert)

D

Davy Marichael

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..
 
B

Bob Barrows [MVP]

Davy said:
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!

.... 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top