DataGrid doesn't display results from DataSet

I am using this code but it doesn't display anthing in the DataGrid after I clicked a submit button

        Dim MyConn As OleDbConnection = New OleDbConnection(ConfigurationSettings.AppSettings("strConn"))

        Dim MyCmd As OleDbCommand = New OleDbCommand("sp_RecordSearch", MyConn)

        MyCmd.CommandType = CommandType.StoredProcedure

        Dim objParam1 As OleDbParameter

        objParam1 = MyCmd.Parameters.Add(txtSearch.Text.Trim(), OleDbType.Char)

        Dim MyDataAdapter As OleDbDataAdapter = New OleDbDataAdapter(MyCmd)

        Dim MyDataSet As DataSet

        Try
            If MyConn.State = ConnectionState.Closed Then
                '   |||||   DB not already Open...so open it
                MyConn.Open()
            End If
            MyDataAdapter.Fill(MyDataSet)
            MyDataGrid1.DataSource = MyDataSet
            MyDataGrid1.DataBind()
        Catch ex As Exception
            'lblMessage.Text = "ERROR?"
        End Try
grind33Asked:
Who is Participating?
 
RobertRFreemanCommented:
It's better to use form designed adapters/datasets.  Here is a tutorial:
http://vsnetdatabinding.blogspot.com/
This will create your parameters for you.

Also specify the datatable in your binding.
MyDataGrid1.DataSource = MyDataSet.Table1  (if you're using a typed dataset as in the tutorial)
or
MyDataGrid1.DataSource = MyDataSet.tables("Table1") (if not using a typed dataset)
0
 
gregoryyoungCommented:
whats the parameter you are passing ? is it actually a char?
0
 
grind33Author Commented:
the parameter is a string taken from a text box.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
gregoryyoungCommented:
why are you passing it as a char?
0
 
grind33Author Commented:
im not, im passing it as a string but there's no string option and ive used it before without any problems
0
 
gregoryyoungCommented:
put a breakpoint after the dataadapter.fill ...

look at the dataset ... whats in it?

0
 
gregoryyoungCommented:
do you have autocolumns on ? or have you defined the columnstyles for your columns ?
0
 
amyhxuCommented:
MyDataGrid1.DataSource = MyDataSet.Tables(0)
 ' remove MyDataGrid1.DataBind()
0
 
grayeCommented:
... not that this has anything to do with what you're asking about....

The DataAdapter has an implied Connection.Open() and Connection.Close(), so there's no need to explicitly test for or open the connection.
0
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.

All Courses

From novice to tech pro — start learning today.