Solved

insert new record into SQL not working

Posted on 2012-03-10
7
351 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now