| | |
SQL insert help!!
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2006
Posts: 2
Reputation:
Solved Threads: 0
Hey guys. i am trying to insert data from a form to a sql database, but this error keeps coming up.
Here is the code.
cheers, michael
VB.NET Syntax (Toggle Plain Text)
Incorrect syntax near ','
VB.NET Syntax (Toggle Plain Text)
Dim AddSwimmer_comm As New SqlCommand( _ "INSERT INTO [MasterRecords] ([APASCID], [FullName], [Gender], [DOB], [21m], [25m], [50m], [100m], [4x21m], [4x50m]) VALUES ( " & apascidbox.Text & ", " & txt_fullname.Text & ", " & txt_birthdate.Text & ", " & gender.Text & ", " & _21.Checked & ", " & _25.Checked & ", " & _50.Checked & ", " & _100.Checked & ", " & medley_4X21.Checked & ", " & medley_4X50.Checked & "))", AddSwimmer_conn) AddSwimmer_conn.Open() AddSwimmer_comm.ExecuteNonQuery() AddSwimmer_conn.Close()
Firstly Sql Server requires single quotes to delimit text. Example:
needs to be:
see you need to concatenate a single quote just before the closing double quote and just after the next openeing double-quote, do same for all text fields in the SQL string.
Also what is the data type in the SQL Table for your measurement fields ? is it bit? I'm not sure if ADO/SQL is able to implicitly convert boolean true/false to a bit 0/1.
VB.NET Syntax (Toggle Plain Text)
VALUES ( " & apascidbox.Text & ",
VB.NET Syntax (Toggle Plain Text)
VALUES ( '" & apascidbox.Text & "',
see you need to concatenate a single quote just before the closing double quote and just after the next openeing double-quote, do same for all text fields in the SQL string.
Also what is the data type in the SQL Table for your measurement fields ? is it bit? I'm not sure if ADO/SQL is able to implicitly convert boolean true/false to a bit 0/1.
Last edited by hollystyles; Jul 16th, 2006 at 4:37 pm.
•
•
Join Date: Jun 2009
Posts: 8
Reputation:
Solved Threads: 0
Here's an example of what to do with boolean statements hope it helps.
I'm new to all this but that line has worked me hope it helps.
VB.NET Syntax (Toggle Plain Text)
sqlcmd = New SqlCommand("INSERT INTO [Employees] (" _ & "[Id], [Name], [Rehire] ) " _ & "VALUES ( " _ & " & idvalue & ", " _ & "'" & namevalue &"', " & & "'" & rehireboolean.tostring & "')", con)
I'm new to all this but that line has worked me hope it helps.
•
•
Join Date: Jul 2009
Posts: 3
Reputation:
Solved Threads: 0
Protected Sub cmdPrihvati_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdPrihvati.Click '''///Action on click on the buton cmdPrihvati in your webForm
''' You must connect to database first.
''' you must heve 3 feilds (txtNaziv, txtAdresa, txtMesto) language of the form is Serbian (english is: txtName, txtAddres, txtTown)
''' you must have Table in the Database. Table's name is KlijentiUpload and she has 3 fields (Naziv, adresa, Mesto)
Dim Naziv As String '' text variable
Dim Adresa As String '' text variable
Dim Mesto As String '' text variable
Dim UpSql As String '' text variable for your new SQL string
Dim Source As AccessDataSource
Naziv = txtNaziv.Text.ToString '' variable /Naziv/ recive txtField's value
If Naziv = "" Then
Response.Write("Niste uneli podatak u Obavezno polje - Naziv." & vbCrLf & "Ponovite unos") ''MsgBox if required field does not value
txtNaziv.BorderWidth = 2 '' change border if required field does not value
txtNaziv.BorderColor = Drawing.Color.Red '' change BorderColor if required field does not value
Exit Sub
Else
txtNaziv.BorderWidth = 1
txtNaziv.BorderColor = Drawing.Color.Gray
End If
Adresa = txtAdresa.Text.ToString '' variable /Adresa/ recive txtField's value
If Adresa = "" Then
Response.Write("Niste uneli podatak u Obavezno polje -Adresa." & vbCrLf & "Ponovite unos")
Exit Sub
End If
Mesto = txtMesto.Text.ToString '' variable /Mesto/ recive txtField's value
If Mesto = "" Then
Response.Write("Niste uneli podatak u Obavezno polje - Mesto." & vbCrLf & "Ponovite unos")
Exit Sub
End If
'' if all ok, you can recived values from text feilds and write into sql
UpSql = "INSERT INTO KlijentiUpload(Naziv, Adresa, Mesto) VALUES ('" + Naziv.ToString + "','" + Adresa.ToString + "', '" + Mesto.ToString + "')"
AccessDataSource1.SelectCommand = UpSql
txtNaziv.Text = ""
txtAdresa.Text = ""
txtMesto.Text = ""
Response.Write("Podaci su uspešno uneti u bazu podataka- Hvala") ''MsgBox if all OK
End Sub
''' You must connect to database first.
''' you must heve 3 feilds (txtNaziv, txtAdresa, txtMesto) language of the form is Serbian (english is: txtName, txtAddres, txtTown)
''' you must have Table in the Database. Table's name is KlijentiUpload and she has 3 fields (Naziv, adresa, Mesto)
Dim Naziv As String '' text variable
Dim Adresa As String '' text variable
Dim Mesto As String '' text variable
Dim UpSql As String '' text variable for your new SQL string
Dim Source As AccessDataSource
Naziv = txtNaziv.Text.ToString '' variable /Naziv/ recive txtField's value
If Naziv = "" Then
Response.Write("Niste uneli podatak u Obavezno polje - Naziv." & vbCrLf & "Ponovite unos") ''MsgBox if required field does not value
txtNaziv.BorderWidth = 2 '' change border if required field does not value
txtNaziv.BorderColor = Drawing.Color.Red '' change BorderColor if required field does not value
Exit Sub
Else
txtNaziv.BorderWidth = 1
txtNaziv.BorderColor = Drawing.Color.Gray
End If
Adresa = txtAdresa.Text.ToString '' variable /Adresa/ recive txtField's value
If Adresa = "" Then
Response.Write("Niste uneli podatak u Obavezno polje -Adresa." & vbCrLf & "Ponovite unos")
Exit Sub
End If
Mesto = txtMesto.Text.ToString '' variable /Mesto/ recive txtField's value
If Mesto = "" Then
Response.Write("Niste uneli podatak u Obavezno polje - Mesto." & vbCrLf & "Ponovite unos")
Exit Sub
End If
'' if all ok, you can recived values from text feilds and write into sql
UpSql = "INSERT INTO KlijentiUpload(Naziv, Adresa, Mesto) VALUES ('" + Naziv.ToString + "','" + Adresa.ToString + "', '" + Mesto.ToString + "')"
AccessDataSource1.SelectCommand = UpSql
txtNaziv.Text = ""
txtAdresa.Text = ""
txtMesto.Text = ""
Response.Write("Podaci su uspešno uneti u bazu podataka- Hvala") ''MsgBox if all OK
End Sub
Last edited by g@sha; Jul 23rd, 2009 at 9:07 am.
![]() |
Similar Threads
- How to insert data into database? (JSP)
- WizardSteps-> SQL Insert -> Grab ID field (ASP.NET)
- SQL Query inserts junk data as well (ASP)
- $rs=mysql_query($sql) or die("error in common.inc.php at line 257"); (PHP)
- Rows not added correctly when using 'INSERT' (PHP)
Other Threads in the VB.NET Forum
- Previous Thread: Debugging Error!!
- Next Thread: time table automation
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
"crystal .net .net2005 30minutes 2005 2008 access application arithmetic array basic binary bing button buttons c# center check code combobox component connectionstring convert crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net dropdownlist error excel file-dialog firewall folder ftp google hardcopy image images inline listview login math memory mobile ms navigate net networking opacity output peertopeervideostreaming picturebox picturebox1 plugin port print printing problem problemwithinstallation project reports" save savedialog searchbox serial server soap sorting sql string studio tcp text textbox timer toolbox trim updown upload usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio web wpf






