OVH Cloud OVH Cloud

ASP -> Database "Insert"

1 réponse
Avatar
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..

1 réponse

Avatar
VANNESTE Xavier
do you have write access to your db
"Davy Marichael" a écrit dans le message de news:
%
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..