Modify a SQL entry with visual basic 2005

This is my first attempt to connect to an SQL database and make some changes.   I need to find row, then change a value.  I have my project setup to make the SQL connection and I can see the data.  This is a console app that will run and make changes to the database.

So my row will look like

Serial number | Info | Available

So I need to find the row by finding the serial number, and then make a change to the available column.  How would I set that up?
chadmanvbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

santhimurthydCommented:
Your question is very simple, but need an some reference to get understand

Please feel free to walk throgh the URL and after this, if you need more info/assistned please revert back

http://www.codeguru.com/vb/gen/vb_database/adonet/article.php/c15033
0
CodeCruiserCommented:
Here is a simple example



Imports System.Data.SqlClient
Dim dbcon As New SqlConnection("your connection string")
dbcon.Open()
Dim dbcmd As New SqlCommand
dbcmd.Connection = dbcon
dbcmd.CommandText = "Update tablename Set columnname=value Where columnname=value"
dbcmd.ExecuteNonQuery()
dbcmd.dispose
dbcon.dispose
0
chadmanvbAuthor Commented:
CodeCruiser,
I'm trying this, but getting an error when making the change.  I have a datagrid view and can see my data when I start the application.  I have a button that I'm using to test my change.  Workstations is my table name, Name is my serial number and also textbox2.text, and Description is what I want to change my value to and also textbox2.text.  I think I have the correct connection string, I cut/pasted that from my data connection.  Here is the code I have for the button.

 'write db
        Dim dbcon As New SqlConnection("Data Source=TestServerSQL;Integrated Security=True")
        dbcon.Open()
        Dim dbcmd As New SqlCommand
        dbcmd.Connection = dbcon
        dbcmd.CommandText = "Update Workstations Set DESCRIPTION=" & TextBox1.Text.Trim & "Where NAME=" & TextBox2.Text.Trim
        dbcmd.ExecuteNonQuery()
        dbcmd.Dispose()
        dbcon.Dispose()


The error is incorrect syntex near name.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

CodeCruiserCommented:
For columns of type varchar, values need to be enclosed in ' ' so try


Also, when concatenating, make sure you add spaces as your query was missing a space before Where.
dbcmd.CommandText = "Update Workstations Set DESCRIPTION='" & TextBox1.Text.Trim & "' Where NAME='" & TextBox2.Text.Trim & "'"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chadmanvbAuthor Commented:
Yippee, it worked!  Thanks so much.  I'm sure this will lead to a bunch more questions soon.
0
CodeCruiserCommented:
Glad to help :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.