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(Configurat ionSetting s.AppSetti ngs("strCo nn"))
Dim MyCmd As OleDbCommand = New OleDbCommand("sp_RecordSea rch", MyConn)
MyCmd.CommandType = CommandType.StoredProcedur e
Dim objParam1 As OleDbParameter
objParam1 = MyCmd.Parameters.Add(txtSe arch.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(MyDataS et)
MyDataGrid1.DataSource = MyDataSet
MyDataGrid1.DataBind()
Catch ex As Exception
'lblMessage.Text = "ERROR?"
End Try
Dim MyConn As OleDbConnection = New OleDbConnection(Configurat
Dim MyCmd As OleDbCommand = New OleDbCommand("sp_RecordSea
MyCmd.CommandType = CommandType.StoredProcedur
Dim objParam1 As OleDbParameter
objParam1 = MyCmd.Parameters.Add(txtSe
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(MyDataS
MyDataGrid1.DataSource = MyDataSet
MyDataGrid1.DataBind()
Catch ex As Exception
'lblMessage.Text = "ERROR?"
End Try
whats the parameter you are passing ? is it actually a char?
ASKER
the parameter is a string taken from a text box.
why are you passing it as a char?
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?
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()
' remove MyDataGrid1.DataBind()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
... 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.
The DataAdapter has an implied Connection.Open() and Connection.Close(), so there's no need to explicitly test for or open the connection.