How do I execute a SQL UPDATE command in VB

I'm sorry to say that I'm a complete noob when it comes to programing and I am at a complete loss as to how to get this to work.

I have been tasked with writting a program that will simply update a database field with the click of a radio button.  There will be 5 radio buttons and when the first button is clicked (as well as the 'update' button below)  I need it to execute an UPDATE query to the field with a '1'.  The second button, when clicked, should UPDATE the field with a '2' and so on and so forth up to 5.  Also I have it update the PictureBox with a new image depending upon which RadioButton I click.

I can see the db through Data Connections.  I've also created a StoredProcedure, but can not, due to a lack of knowledge, get it to execute with a RadioButton click though at this point I don't think I want to use a SProc right now.

I currently am using Visual Studio 2008, Visual Basic and have a database called 'defcon' on a SQL2005 server called DEV\SQL2005.  There is a Table called 'Level' and a field named 'defcon'.  I've attached the code that I have so far.

Any help would be appreciated!
Public Class Form1
    Dim SetLevel As String = "Site Availability Level Changed"
 
    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)
 
    End Sub
 
    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
 
    End Sub
 
    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        PictureBox1.Image = Image.FromFile(My.Computer.FileSystem.SpecialDirectories.MyPictures & "pic1.jpg")
 
    End Sub
 
    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        PictureBox1.Image = Image.FromFile(My.Computer.FileSystem.SpecialDirectories.MyPictures & "pic2.jpg")
    End Sub
 
    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
        PictureBox1.Image = Image.FromFile(My.Computer.FileSystem.SpecialDirectories.MyPictures & "pic3.jpg")
    End Sub
 
    Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
        PictureBox1.Image = Image.FromFile(My.Computer.FileSystem.SpecialDirectories.MyPictures & "pic4.jpg")
    End Sub
 
    Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged
        PictureBox1.Image = Image.FromFile(My.Computer.FileSystem.SpecialDirectories.MyPictures & "pic5.jpg")
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox(SetLevel)
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
    End Sub
End Class

Open in new window

jekky_rockyAsked:
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.

MezillinuCommented:
Hi, follow my code below, to do an update SQL in VB.NET

You need to apply it in your case, but it is an easy approach, and you could use it...


This is done in oleDB, but all you have to do it swtich to SQLConnection, but the syntax for SQL in this case is the same.

You should cope with this example

cheers, post if you need any more help
Try
            Dim SQL_Connection As New OleDbConnection
            Dim SQL_Command As New OleDbCommand
            Dim sSQL_Command As String = ""
 
            Dim tools As New Tools
            Dim databaseConnectionString As String = tools.getXmlValue("DBConnStringErrorHandlingException")
            SQL_Connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & databaseConnectionString
            SQL_Command.Connection = SQL_Connection
 
            'create the insert 
            sSQL_Command = "update tbl_EmailTemplates " & _
                           "  set TemplateContent = @templatecontent " & _
                           " where TemplateName = @templatename"
 
            With SQL_Command
                .Parameters.AddWithValue("@TemplateName", Me.txtTemplateName.Text)
                .Parameters.AddWithValue("@TemplateContent", Me.htmlEmailTemplateEditor.Value.ToString)
                .CommandText = sSQL_Command
            End With
 
            SQL_Connection.Open()
            SQL_Command.ExecuteNonQuery()
            SQL_Connection.Close()
 
            SQL_Command.Dispose()
            SQL_Connection.Dispose()
        Catch ex As Exception
            Me.lblStatus.Text = ex.Message
 
        End Try
    End Sub

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
hongjunCommented:
Change the above OleDbConnection to SqlConnection
Change the above OleDbCommand to SqlCommand

For connection string, try below

http://www.connectionstrings.com
0
jekky_rockyAuthor Commented:
Thanks guys.  I'll take another stab at it and see how it goes.  I have a feeling I might have to come back for some more hand holding.
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
Visual Basic Classic

From novice to tech pro — start learning today.