Webform help

Ok I am new to .net I have a stored procedure that returns a set of rows.  My Designview webform has labels textboxs and a button along with a datagrid.  I want to be able to search the database with the click of the search button.  I think as long as I call the stored proc it will take care of the searching.  Could someone help/show me the code for the following:  (I will be using ODBC connection)  

- Calling the stored procedure
-Creating and populating a dataset
- And giving the dataset to gridview

Please help me with this code!  thank you :o)
yabakingdaAsked:
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.

YZlatCommented:
This function will take care of the first 2. Then just set the DataSource of the GridView to a DataSet returned by the function:

Public Function RunSelectStoredProc(ByVal procName As String, ByVal parms As OdbcParameter(), ByVal strConn As String) As DataSet
        Dim conn As OdbcConnection = GetConnection(strConn)
        Dim result, output As Integer
        Dim cmd As OdbcCommand = New OdbcCommand(procName, conn)
        Dim da As New OdbcDataAdapter
        Dim ds As New DataSet
        ' Configure the OdbcCommand object
        If Not cmd Is Nothing Then
            Try
                With cmd
                    .Connection = conn
                    .CommandType = CommandType.StoredProcedure      ''Set type to StoredProcedure
                    .CommandText = procName                    ''Specify stored procedure to run

                    '' Clear any previous parameters from the Command object
                    Call .Parameters.Clear()

                    '' Loop through parameter collection adding parameters to the command object
                    If Not (parms Is Nothing) Then
                        For Each OdbcParm As OdbcParameter In parms
                            If Not OdbcParm Is Nothing Then
                                cmd.Parameters.Add(OdbcParm)
                            End If
                        Next
                    End If
                End With
            Catch ex As OdbcException
                Console.WriteLine("Error adding parameters to the stored procedure " & procName & ": " & ex.Message)
            End Try
        End If

        Try
            da.SelectCommand = cmd
            ''make sure command does not timeout
            da.SelectCommand.CommandTimeout = 0
            da.Fill(ds)
        Catch ex As Exception
            Console.Write("Error executing stored procedure " & procName & ": " & ex.Message)
        Finally
            conn.Close()
        End Try
        RunSelectStoredProc = ds
    End Function


Function GetConnection(ByVal strConn As String) As OdbcConnection
        Try
            conn = New OdbcConnection(strConn)
            conn.Open()
        Catch ex As OdbcException
            Console.Write("Odbc ERROR: " & ex.Message)
        Catch ex As Exception
            Console.Write("ERROR: " & ex.Message)
        End Try
        GetConnection = conn
    End Function
YZlatCommented:
first you'll need to create an array of parameters:

Dim parms(2) As OdbcParameter
parms(0) = New OdbcParameter("@paramName1", variable1)
 parms(1) = New OdbcParameter("@paramName2", variable2)
parms(2) = New OdbcParameter("@paramName3", variable3)

then call the function

Dim ds as new dataset
ds=RunSelectStoredProc("STOREDPROCEDURENAME", parms, "your odbc connection string")

then

DataGrid1.DataSource=ds.DefaultView
DataGrid1.DataBind

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
yabakingdaAuthor Commented:
Im using VS 2005 so some of the odbc parts are showing some errors

So on this part:
Dim parms(2) As OdbcParameter
parms(0) = New OdbcParameter("@paramName1", variable1)
 parms(1) = New OdbcParameter("@paramName2", variable2)
parms(2) = New OdbcParameter("@paramName3", variable3)

then call the function

Dim ds as new dataset
ds=RunSelectStoredProc("STOREDPROCEDURENAME", parms, "your odbc connection string")

then

DataGrid1.DataSource=ds.DefaultView
DataGrid1.DataBind

This is creating the dataset and filling it and populating the gridview?
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.