Hi..i want helpful to understand some lines in this code..this code to insert record in DB using SQL statement(INSERT)and ADO.NET classes:
dim insCom as new OleDb.OleDbCommand()
insCom.CommandTex="INSERT INTO Book(cID,bName,Price)
Values("& TextCid.Text & ",[red]'" & TextName.Text & "'[/red]," &
TextPrice.Text & ")"
[red]in previous 2 lines my questions:
1- i don't understand why single quote is used to insert string and when i don't write this quote it caused error?
2-what about & character?[/red]
insCom.Connection=OleDbConnection1
OleDbConnection1.Open()
insCom.ExecuteNonQuery()
OleDbConnection1.Close()
MessageBox.Show("process succeed")
clear()
End Sub
plz answer me in hithermost time as you can..and Thax very much
Best regards ..program_agent
Comments
you are using this one :
insCom.CommandTex="INSERT INTO Book(cID,bName,Price)
Values("& TextCid.Text & ",'" & TextName.Text & "'," &
TextPrice.Text & ")"
in previous 2 lines my questions:
1- i don't understand why single quote is used to insert string and when i don't write this quote it caused error?
ans: we use single quote in insert statement because when we fired a simple quey in sql we always use single quote for string data.
this is a standerd rule of sql.
in above code when this query fired on database using oledb(provider)
it's cause error if you don't use single quote.
Regards
Satyadev Singh
Please join our group
http://groups-beta.google.com/group/Devinfoway
[b][red]This message was edited by dnroy at 2005-4-16 3:5:18[/red][/b][hr]
[b][red]This message was edited by dnroy at 2005-4-16 3:4:14[/red][/b][hr]
: Hi..i want helpful to understand some lines in this code..this code to insert record in DB using SQL statement(INSERT)and ADO.NET classes:
: dim insCom as new OleDb.OleDbCommand()
: insCom.CommandTex="INSERT INTO Book(cID,bName,Price)
: Values("& TextCid.Text & ",[red]'" & TextName.Text & "'[/red]," &
: TextPrice.Text & ")"
: [red]in previous 2 lines my questions:
: 1- i don't understand why single quote is used to insert string and when i don't write this quote it caused error?
: 2-what about & character?[/red]
:
: insCom.Connection=OleDbConnection1
: OleDbConnection1.Open()
: insCom.ExecuteNonQuery()
: OleDbConnection1.Close()
: MessageBox.Show("process succeed")
: clear()
: End Sub
:
: plz answer me in hithermost time as you can..and Thax very much
: Best regards ..program_agent
:
: Answer: from D.N.Roy ----16 April,2005
To store string value in the database single quote in SQL Query is used,where as for integer value it does not need single quote.
: dim insCom as new OleDb.OleDbCommand()
: insCom.CommandTex="INSERT INTO Book(cID,bName,Price)
: Values("& TextCid.Text & ",[red]'" & TextName.Text & "'[/red]," &
: TextPrice.Text & ")"
: [red]in previous 2 lines my questions:
: 1- i don't understand why single quote is used to insert string and when i don't write this quote it caused error?
: 2-what about & character?[/red]
:
: insCom.Connection=OleDbConnection1
: OleDbConnection1.Open()
: insCom.ExecuteNonQuery()
: OleDbConnection1.Close()
: MessageBox.Show("process succeed")
: clear()
: End Sub
:
: plz answer me in hithermost time as you can..and Thax very much
: Best regards ..program_agent
:
:
Hi,
Can I ask u a question? How do u insert a varchar variable in Sqlserver2000 by wrtiting query.
Sql Syntax is such that...
If u don't follow the sytax it gives error, U can't insert data Right!That's what happening here.
So in the front end for string variable we need to append '
Hope U understood