Solved

insert new record into SQL not working

Posted on 2012-03-10
7
354 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

808 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