Link to home
Start Free TrialLog in
Avatar of printmedia
printmedia

asked on

Inserting windows form data into SQL Server 2008 table in vb.net

Hi all.

I have the code below that inserts data into a SQL table using Visual Studio 2010. It works perfectly but I had a question concerning the & and + in the Insert Into part of the code.

In my code I used the &, but I've seen online some people use + and I tested my code with + and it also worked fine.

Does it matter which one I use, what is the best practice? Thank you in advance.

Dim con As New SqlConnection
        Dim cmd As New SqlCommand

        con.ConnectionString = "Data Source=myserver;Initial Catalog=mydb;Integrated Security=True"

        con.Open()

        cmd.Connection = con

        cmd.CommandText = "INSERT INTO ItemQuote(MasterItemNumber) VALUES ('" & txtMasterItemNo.Text & "')"
        cmd.ExecuteNonQuery()

        MsgBox("Item has been submitted")

        con.Close()

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Craig Wagner
Craig Wagner
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial