Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my insert query is

VB
Private Sub addnew_Click()
str = "insert into profile(rollno,fathername,occupation,contactno,mothername,mother's occupation,annualincome,religion,caste,address,city,state)values(" & rno.Text & ", ' " & fname.Text & " ',' " & occu.Text & " ',' " & cno.Text & " ' ,' " & mname.Text & " ',' " & occupation.Text & " ', ' " & ain.Text & " ', ' " & religion.Text & " ', ' " & caste.Text & " ', ' " & address.Text & " ',' " & city.Text & " ',' " & state.Text & " ')"
cn.Execute (str)
MsgBox ("DETAILS ADDED ")
End Sub


while executing this i got a runtime error,
can anyone help in correcting this runtime error.
THANKS IN ADVANCE............
Posted
Comments
[no name] 16-Sep-12 10:53am    
And that error would be...? It helps to give us all of the information...
Your error would probably go away if you used parameterized queries like you should be using to prevent SQL injection attacks.

1 solution

Did you really name a column "mother's occupation"?

I am surprised that SQL server let you do that. If you did, then you will need to enclos it in '[' and ']' characters:
SQL
str = "insert into profile(rollno,fathername,occupation,contactno,mothername,[mother's occupation],annualincome,religion,caste,address,city,state)...


But also, do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900