hi it 's working but the Grid view not disp.lay the details

Dim cn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;" & "Data Source=D:\Task_one_one\TaskNew\TaskNew\App_Data\db1.mdb")
        cn.Open()
        Try
            Dim myTable As DataTable = New DataTable("MyTable")
            'Dim ds As DataSet = New DataSet
            myTable.Columns.Add(New DataColumn("Emp Id"))
            myTable.Columns.Add(New DataColumn("Start Time"))
            myTable.Columns.Add(New DataColumn("End Time"))
            myTable.Columns.Add(New DataColumn("Hours"))
            myTable.Columns.Add(New DataColumn("Date"))
            Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Log WHERE (Emp_id=" & TextBox1.Text & ")", cn)
            Dim dr As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.Default)
            Dim myRow As DataRow
            While dr.Read()
                myRow = myTable.NewRow
                myRow.Item(0) = dr(0)
                myRow.Item(1) = dr(1)
                myRow.Item(2) = dr(2)
                myRow.Item(3) = dr(3)   '
                myRow.Item(4) = dr(4)
                myTable.Rows.Add(myRow)
            End While
            dr.Close()
            'Add datatable to datagridview
            Dim myData4 As DataTable = myTable
            Dim ds = New DataSet()
            ds.Tables.Add(myData4)
            GridView1.DataSource = myData4
            'GridView1.DataSource = myTable
            GridView1.DataBind()

        Catch ex As Exception
            'MsgBox(ex.ToString)  'Show error when something goes wrong
            Label1.Text = ex.ToString

        End Try
        cn.Close()

put break point on line 28 and see data is there in mydata4? becuase ur assigning it to Mytable which is new table. so i suspect Mydata4 is blank.

Pgmer, he has already populated the MyTable table above, he needs to set the mydata4 table to be a copy of the Mytable table.
Dim Mydata4 as DataTable = MyTable.Copy This will copy the data structure and data from the MyTable to Mydata4.

Why though do you create and populate a table then create another table and then copy it? Why not just use the first table?

Anyway, it is possible that your query isn't actually pulling anything back before going into the While dr.Read loop, you should check if dr.HasRows
If not then throw up a message box telling you there is no data then you know if it is returning data or not.

This article has been dead for over six months. Start a new discussion instead.