Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

insert new record into SQL not working

Posted on 2012-03-10
7
Medium Priority
?
358 Views
Last Modified: 2012-03-14
Hi

I am trying to create a small software license database and when i try and insert a new record using


        Dim connstring As String = Nothing

        Dim sqlconn As New SqlConnection
        Dim sqlcmd As New SqlCommand

        connstring = "server=simon-pc;database=licenses;trusted_connection=yes;"

        sqlconn.ConnectionString = connstring

        sqlconn.Open()
        sqlcmd.Connection = sqlconn

        sqlcmd.CommandText = "insert into licenses (Manuafacture, appname, version, username, ci, license, po, invoice, date_logged) values(" & manufacturerCb.SelectedValue & "," & _
            applicationNameCb.SelectedValue & "," & verstionTxt.Text & "," & assignedUserTxt.Text & "," & machineNameTxt.Text & "," & licenseKeyTxt.Text & "," & poNumberTxt.Text & "," & _
            invoiceNumberTxt.Text & "," & dateloggedDtp.Value & ");"


        sqlcmd.ExecuteNonQuery()
        sqlconn.Close()



I receive the error message

Incorrect syntax near ','.

using VS2010 in the autos window the last place this gets to is version.

Can anyone shed any light on to why I am getting this please?

Thanks

Simon
0
Comment
Question by:SimonPrice33
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 37704751
Have you spelt this control correctly ? verstionTxt.Text
Are you maybe missing a continuation character after the & on the 3rd line
0
 
LVL 8

Accepted Solution

by:
pdd1lan earned 2000 total points
ID: 37704759
you might need to put a single quote around the text value


sqlcmd.CommandText = "insert into licenses (Manuafacture, appname, version, username, ci, license, po, invoice, date_logged) values(' " & manufacturerCb.SelectedValue & " ' , ' " & _
            applicationNameCb.SelectedValue & " ', ' " & verstionTxt.Text & " ', ' " & assignedUserTxt.Text & " ', ' " & machineNameTxt.Text &  " ', ' " & licenseKeyTxt.Text & " ', ' " & poNumberTxt.Text & " ', ' " & _
 invoiceNumberTxt.Text & " ' , #" & dateloggedDtp.Value & "# );"
0
 

Author Comment

by:SimonPrice33
ID: 37704769
thanks guys, will try now, spelling of version is correct now...  will try using the single quotes too...

one question, what does the # represent?

Thanks
Simon
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

Author Closing Comment

by:SimonPrice33
ID: 37704775
Bonza! thanks :)

worked a charm with single quotes, changed the # to ' too :)

thanks

Simon
0
 
LVL 8

Expert Comment

by:pdd1lan
ID: 37704777
you don't have to use a sing quote around value if value is number, but it requires the value is text value.  "#" around variable for date field value.
0
 

Author Comment

by:SimonPrice33
ID: 37718788
hi, the spelling mistake was in my post here, actual code was correct, solution that was awarded the points was the correct and in full..
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question