Link to home
Start Free TrialLog in
Avatar of grind33
grind33

asked on

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
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

whats the parameter you are passing ? is it actually a char?
Avatar of grind33
grind33

ASKER

the parameter is a string taken from a text box.
why are you passing it as a char?
Avatar of grind33

ASKER

im not, im passing it as a string but there's no string option and ive used it before without any problems
put a breakpoint after the dataadapter.fill ...

look at the dataset ... whats in it?

do you have autocolumns on ? or have you defined the columnstyles for your columns ?
MyDataGrid1.DataSource = MyDataSet.Tables(0)
 ' remove MyDataGrid1.DataBind()
ASKER CERTIFIED SOLUTION
Avatar of RobertRFreeman
RobertRFreeman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
... 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.