Help: Insert record into database

G

Guest

I have following code, but I do not know where the problem is. Thank you for
any help.

David

----Code---
'connection
conn = New SqlConnection _
("data source=localhost;integrated security=true;initial
catalog=DemoCRQdatabase")
'command
Dim propertyCMD As New SqlCommand("INERT INTO " &
txtProperty.Text & "(Code, Name) VALUES(" & txtCode.Text & ", " &
txtName.Text & ")", conn)
'command type: CommandType.Text
propertyCMD.CommandType = CommandType.Text
'Open connection and execute the insert statement
conn.Open()
propertyCMD.ExecuteNonQuery()
conn.Close()

----
----error message-----
Incorrect syntax near the keyword 'INTO'.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near
the keyword 'INTO'.

Source Error:


Line 66: propertyCMD.CommandType = CommandType.Text
Line 67: 'Open connection and execute the insert statement
Line 68: conn.Open()
Line 69: propertyCMD.ExecuteNonQuery()
Line 70: conn.Close()


Source File: c:\inetpub\wwwroot\Demo\AddClassProperty.aspx.vb Line: 68
 
G

Guest

INERT is spelled INSERT.

Do use stored procedues over direct queries.
The presented code is really open to injection attacks!
 

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

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top