[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

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
0
grind33
Asked:
grind33
1 Solution
 
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
 
gregoryyoungCommented:
why are you passing it as a char?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now