SQL insert help!!

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2006
Posts: 2
Reputation: mikkime23 is an unknown quantity at this point 
Solved Threads: 0
mikkime23 mikkime23 is offline Offline
Newbie Poster

SQL insert help!!

 
0
  #1
Jul 16th, 2006
Hey guys. i am trying to insert data from a form to a sql database, but this error keeps coming up.
  1. Incorrect syntax near ','
Here is the code.
  1. Dim AddSwimmer_comm As New SqlCommand( _
  2. "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)
  3. AddSwimmer_conn.Open()
  4. AddSwimmer_comm.ExecuteNonQuery()
  5. AddSwimmer_conn.Close()
cheers, michael
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: SQL insert help!!

 
0
  #2
Jul 16th, 2006
Firstly Sql Server requires single quotes to delimit text. Example:
  1. VALUES ( " & apascidbox.Text & ",
needs to be:
  1. 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.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 2
Reputation: mikkime23 is an unknown quantity at this point 
Solved Threads: 0
mikkime23 mikkime23 is offline Offline
Newbie Poster

Re: SQL insert help!!

 
0
  #3
Jul 17th, 2006
yes, it is a bit. i have also been getting errors for the false and true statements. thanks for the reply.

Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 8
Reputation: everettnewell is an unknown quantity at this point 
Solved Threads: 0
everettnewell everettnewell is offline Offline
Newbie Poster

Re: SQL insert help!!

 
0
  #4
Jun 13th, 2009
Here's an example of what to do with boolean statements hope it helps.

  1. sqlcmd = New SqlCommand("INSERT INTO [Employees] (" _
  2. & "[Id], [Name], [Rehire] ) " _
  3. & "VALUES ( " _
  4. & " & idvalue & ", " _
  5. & "'" & namevalue &"', " &
  6. & "'" & rehireboolean.tostring & "')", con)

I'm new to all this but that line has worked me hope it helps.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 26
Reputation: LennieKuah is an unknown quantity at this point 
Solved Threads: 0
LennieKuah LennieKuah is offline Offline
Light Poster

Re: SQL insert help!!

 
0
  #5
Jun 16th, 2009
Hi All,
I am experiencing the same problems and thanks for the suggestions. I got it fixed following the samples.


Cheers,
Lennie
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 3
Reputation: suresh bangaru is an unknown quantity at this point 
Solved Threads: 0
suresh bangaru suresh bangaru is offline Offline
Newbie Poster

Re: SQL insert help!!

 
0
  #6
Jun 24th, 2009
sqlcmd = New SqlCommand("INSERT INTO tablename (field1,field2,field3,..)values('" & textbox1.text & "','" & textbox2.text & "','" & textbox3.text & "',...),con)
cmd.ExecuteNonQuery()
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 3
Reputation: g@sha is an unknown quantity at this point 
Solved Threads: 0
g@sha g@sha is offline Offline
Newbie Poster

Re: SQL insert help!!

 
0
  #7
Jul 23rd, 2009
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
Last edited by g@sha; Jul 23rd, 2009 at 9:07 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC