Welcome Guest Search | Active Topics | Sign In | Register

Grid population from SQL datatable Options
Mike
Posted: Thursday, February 25, 2016 12:24:53 PM
Rank: Newbie
Groups: Member

Joined: 2/25/2016
Posts: 3
Being new to the EO.web product I cannot understand where I am going wrong. I have built a grid, created the column headers, and used a simple select statement to get data from an existing SQL db just to get a feel for the grid product. The grid appears with the column headers and the correct amount of lines returned by the sql select. However, no data is in the cells. I have used multiple versions of code to select the data and doing the databind. Same results. No errors just no data in the grid. I have also validated by other code that reads the returned dataset that data is present.
The code here represents the sql and databind.
Where am I going wrong here?

Thank you for any help. Mike

Code: Visual Basic.NET
Version 1:


        Dim SQLStatement As String = "SELECT TOP(3) * FROM cotts.dbo.tbltimecard"    ' where empid = '999222' " (used to generate no data)
        Dim con = New SqlConnection(MyConnection)
        Dim cmd = New SqlCommand(SQLStatement, con)
        cmd.CommandType = CommandType.Text
        con.Open()
        Grid1.DataSource = cmd.ExecuteReader()
        Grid1.DataBind()
        con.Close()
        con.Dispose()


Version 2:

        Dim SQLStatement As String = "SELECT TOP(3) * FROM cotts.dbo.tbltimecard" ' where empid = '999222' "
        Dim myCmd As SqlDataAdapter = New SqlDataAdapter(SQLStatement, NewConnection)
        Dim mydata As New DataTable
        myCmd.Fill(mydata)
        Grid1.DataSource = mydata
        Grid1.DataBind()
eo_support
Posted: Thursday, February 25, 2016 2:34:31 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

You need to explicitly defines the columns and set each column's DataField property. Our Grid does not automatically generate columns or bind data field like ASP.NET's DataGrid control. So you must set them explicitly.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.