In an ASP.NET web page I am trying to use a set of variables to create a new row in a database using just SQL. The variables are:
Dim strDescription as String
Dim decUnitCost, decRetailPrice, decTotalValuePurchased as Decimal
Dim intTotalQuantityPurchased as Integer
and they are exactly as specified in the database table.
This is my code for the insert (which is in a function, the first part of which sets values into the variables and executes perfectly):
Dim sqlConn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("StockControlConnect").ToString())
' open the connection
sqlConn.Open()
Dim strSQL As String
Dim objCmd As New System.Data.SqlClient.SqlCommand
strSQL = "INSERT INTO Chains (Description, UnitCost, RetailPrice, TotalQuantityPurchased, TotalValuePurchased) VALUES (@Description, @UnitCost, @RetailPrice, @TotalQuantityPurchased, @TotalValuePurchased)"
objCmd.Connection = sqlConn
objCmd.CommandText = strSQL
objCmd.CommandType = CommandType.Text
objCmd.Parameters.Add("@Description",Data.SqlDbType.varchar).value=strDescription
objCmd.Parameters.Add("@UnitCost",Data.SqlDbType.Decimal).value=decUnitCost
objCmd.Parameters.Add("@RetailPrice",Data.SqlDbType.Decimal).value=decRetailPrice
objCmd.Parameters.Add("@TotalValuePurchased",Data.SqlDbType.Decimal).value=decTotalValuePurchased
objCmd.Parameters.Add("@TotalQuantityPurchased",Data.SqlDbType.Int).value=intTotalQuantityPurchased
Try
objCmd.ExecuteNonQuery()
Message.Text = "Record Update Sucessful."
Catch ex As Exception
Message.Text = "Record Cannot Insert : Error ("& ex.Message & strSQL &")"
End Try
sqlConn.Close()
sqlConn = Nothing
-------------------------------
On compilation I get the error message:
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: 'CommandType' is not declared. It may be inaccessible due to its protection level.
Source Error:
Line 82: objCmd.Connection = sqlConn
Line 83: objCmd.CommandText = strSQLLine 84: objCmd.CommandType = CommandType.TextLine 85:
Line 86: objCmd.Parameters.Add("@Description",Data.SqlDbType.varchar).value=strDescription
II cannot see what I am doing wrong.