Solved

insert new record into SQL not working

Posted on 2012-03-10
7
353 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
  • 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 500 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

776 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