Hi,
I am going through a tutorial on ASP.Net ( used ASP for a long time) and I can't figure out why I keep getting an error when I try to update or insert a record.
The table is called Models and the fields are:
Model - String
BasePrice - String
Catalog - String
Default_PN - String
I made all of the fields string to make things easier at this time.
Here is the error and the printed out SQL statement:
Syntax error in INSERT INTO statement. SQL= INSERT INTO Models (Model, BasePrice, Catalog, Default_PN) VALUES ( '1847','2295','1847','1847-0000000000000')
An here is the ASP code:
sub Submit(Sender as Object, e as EventArgs)
dim i, j as integer
dim params(7) as string
dim strText as string
dim blnGo as boolean = true
j=0
for i = 0 to AddPanel.Controls.Count -1
if AddPanel.controls(i).GetType IS GetType(TextBox) then
strText = Ctype(AddPanel.Controls(i), TextBox).Text
if strText <>"" then
params(j) = strText
else
blnGo=false
lblMessage.Text = lblMessage.Text & _
"You forgot to enter a value for " & _
AddPanel.Controls(i).ID & "<p>"
lblMessage.Style("Forecolor")="Red"
end if
j = j +1
end if
next
if not blnGo then
exit sub
end if
dim strSql as string = "INSERT INTO Models (Model, BasePrice, Catalog, Default_PN)" & _
" VALUES ( '" & params(0) & "','" & params(1) & "','" & params(2) & "','" & params(3) & "')"
lblMessage2.Text = strSql
ExecuteStatement(strSql)
FillDataGrid()
end sub
function ExecuteStatement(strSQL)
dim objCmd as new OleDbCommand(strSQL, objConn)
try
objCmd.Connection.Open()
objCmd.ExecuteNonQuery()
catch ex as FormatException
lblMessage.Text = ex.Message & " " & strSQL
catch ex as OleDbException
lblMessage.Text = ex.Message & VBCRLF & "SQL= " & strSQL
catch ex as Exception
lblMessage.Text = ex.Message & strSQL
end try
objCmd.Connection.Close()
end function
I set the permissions on the database to everyone full control to take that out of the picture.
Any help would be appreciated.
I am going through a tutorial on ASP.Net ( used ASP for a long time) and I can't figure out why I keep getting an error when I try to update or insert a record.
The table is called Models and the fields are:
Model - String
BasePrice - String
Catalog - String
Default_PN - String
I made all of the fields string to make things easier at this time.
Here is the error and the printed out SQL statement:
Syntax error in INSERT INTO statement. SQL= INSERT INTO Models (Model, BasePrice, Catalog, Default_PN) VALUES ( '1847','2295','1847','1847-0000000000000')
An here is the ASP code:
sub Submit(Sender as Object, e as EventArgs)
dim i, j as integer
dim params(7) as string
dim strText as string
dim blnGo as boolean = true
j=0
for i = 0 to AddPanel.Controls.Count -1
if AddPanel.controls(i).GetType IS GetType(TextBox) then
strText = Ctype(AddPanel.Controls(i), TextBox).Text
if strText <>"" then
params(j) = strText
else
blnGo=false
lblMessage.Text = lblMessage.Text & _
"You forgot to enter a value for " & _
AddPanel.Controls(i).ID & "<p>"
lblMessage.Style("Forecolor")="Red"
end if
j = j +1
end if
next
if not blnGo then
exit sub
end if
dim strSql as string = "INSERT INTO Models (Model, BasePrice, Catalog, Default_PN)" & _
" VALUES ( '" & params(0) & "','" & params(1) & "','" & params(2) & "','" & params(3) & "')"
lblMessage2.Text = strSql
ExecuteStatement(strSql)
FillDataGrid()
end sub
function ExecuteStatement(strSQL)
dim objCmd as new OleDbCommand(strSQL, objConn)
try
objCmd.Connection.Open()
objCmd.ExecuteNonQuery()
catch ex as FormatException
lblMessage.Text = ex.Message & " " & strSQL
catch ex as OleDbException
lblMessage.Text = ex.Message & VBCRLF & "SQL= " & strSQL
catch ex as Exception
lblMessage.Text = ex.Message & strSQL
end try
objCmd.Connection.Close()
end function
I set the permissions on the database to everyone full control to take that out of the picture.
Any help would be appreciated.