Visual Basic SQL query

Hi
I am new to VB and would like to query an sql database using any 1,2 or 3 values entered into 3 textbox controls, how can I write this query using visual studio 2010
LVL 1
sykotexAsked:
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.

Den_HBRCommented:
What code do you already have?
EYoungCommented:
Imports System.Data.SqlClient

Example using a stored procedure:
            Using connSQL As New SqlConnection(My.Settings.SQLConnection)
                mWork_String_1 = "MAPS_GB_Get_One_Parent_Offer"
                Using cmdSQL As New SqlCommand(mWork_String_1, connSQL)
                    cmdSQL.CommandType = CommandType.StoredProcedure
                    cmdSQL.CommandText = mWork_String_1
                    cmdSQL.Parameters.Add("@Parent_Offer", SqlDbType.Char).Value = mParent_Offer
                    connSQL.Open()
                    cmdSQL.ExecuteNonQuery()
                    daMAPS_GB_Associated_Versions = New SqlDataAdapter(cmdSQL)
                    dtMAPS_GB_Associated_Versions = New DataTable
                    daMAPS_GB_Associated_Versions.Fill(dtMAPS_GB_Associated_Versions)
                    Dim drMAPS_GB_Associated_Versions As DataRow
                    For Each drMAPS_GB_Associated_Versions In dtMAPS_GB_Associated_Versions.Rows
                        txtWomens_Offer.Text = Trim(drMAPS_GB_Associated_Versions("Child1_Offer").ToString)
                        txtMens_Offer.Text = Trim(drMAPS_GB_Associated_Versions("Child2_Offer").ToString)
                        txtOther_Offer.Text = Trim(drMAPS_GB_Associated_Versions("Child3_Offer").ToString)
                        cboYear.Text = Trim(drMAPS_GB_Associated_Versions("Offer_Year").ToString)
                        If drMAPS_GB_Associated_Versions("Offer_Season").ToString = "S" Then
                            rbtSpring.Checked = True
                        Else
                            rbtFall.Checked = True
                        End If
                    Next drMAPS_GB_Associated_Versions
                    cmdSQL.Dispose()
                    connSQL.Close()
                    connSQL.Dispose()
                    GC.Collect()
                End Using
            End Using

Example using a command text to do a select:
            Using connSQL As New SqlConnection(My.Settings.SQLConnection)
                mWork_String_1 = "SELECT * FROM Table1 " _
                                              "WHERE Current_Year = '" & txtYear.Text & "'"
                Using cmdSQL As New SqlCommand(mWork_String_1, connSQL)
                    connSQL.Open()
                    cmdSQL.ExecuteNonQuery()
                    connSQL.Close()
                End Using
            End Using
EYoungCommented:
Forgot the ampersand...

Example using a command text to do a select:
            Using connSQL As New SqlConnection(My.Settings.SQLConnection)
                mWork_String_1 = "SELECT * FROM Table1 " _
                                              & "WHERE Current_Year = '" & txtYear.Text & "'"
                Using cmdSQL As New SqlCommand(mWork_String_1, connSQL)
                    connSQL.Open()
                    cmdSQL.ExecuteNonQuery()
                    connSQL.Close()
                End Using
            End Using

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
sykotexAuthor Commented:
cheers, looks like what i need
One last thing if my connection string in my web.config is clientsConnectionString
What would the line below be?

Using connSQL As New SqlConnection(My.Settings.SQLConnection)
EYoungCommented:
Not sure I understand your question.  Can you restate it another way?
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.NET

From novice to tech pro — start learning today.