Data in DataSet but GridView will not display

Discussion in 'ASP .Net' started by Adam Sandler, Feb 16, 2007.

  1. Adam Sandler

    Adam Sandler Guest

    Hello,

    Prior to posting I looked at http://groups.google.com/group/
    microsoft.public.dotnet.framework.aspnet/browse_thread/thread/
    d8d5ae243614085e/d4fd6c4a5aa56f75

    http://groups.google.com/group/micr...read/thread/abb4bcc39312a388/2de51eba9a0bcfd6

    Hello,

    I'm having a problem with getting a GridView to display data. Debug
    shows there is indeed data in the DataSet behind the grid (more on
    that later). But after DataBind() is called, the grid is not
    displayed on the page.

    On the page, here's the markup:

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:devConnectionString %>"
    SelectCommand="SELECT * FROM [DataChron] WHERE ([SensorID] =
    @SensorID)">

    <SelectParameters>
    <asp:parameter Name="SensorID" Type="Int32" />
    </SelectParameters>
    </asp:SqlDataSource>
    <asp:GridView ID="GridView1" runat="server"></asp:GridView>

    Here's there web.config entry:

    <connectionStrings>
    <add name="devConnectionString" connectionString="Data
    Source=CSFDCRW\SQLEXPRESS;Initial Catalog=dev;Integrated
    Security=True"
    providerName="System.Data.SqlClient" />
    </connectionStrings>

    in the codebehind here's some of the code:

    Dim mySensor As New Sensor
    Me.GridView1.DataSource = mySensor.getSensorData(s)
    Me.GridView1.DataBind()

    and here is the method in Sensor:

    Function getSensorData(ByVal s As String) As Data.DataSet
    Dim connStringName As String = "devConnectionString"
    Dim connString As String = _

    ConfigurationManager.ConnectionStrings(connStringName).ConnectionString

    Dim myConnection As New Data.SqlClient.SqlConnection(connString)

    Dim sql As String = "SELECT * FROM [DataChron] WHERE ([SensorID] =
    '" & s & "')"

    Dim myCommand As New Data.SqlClient.SqlCommand(sql, myConnection)

    Dim myDataSet As New Data.DataSet

    Dim myAdapter As New Data.SqlClient.SqlDataAdapter(myCommand)
    myAdapter.Fill(myDataSet)

    getSensorData = myDataSet

    myConnection.Close()
    End Function


    During debug, for the line:

    "SELECT * FROM [DataChron] WHERE ([SensorID] = '" & s & "')"

    the Autos window days:

    SELECT * FROM [DataChron] WHERE ([SensorID] = '7747')

    and if I paste that SQL statement into a SQL pane in SQL Server
    Management Studio, I get 3 rows back!

    stepping into this line:

    getSensorData = myDataSet

    the Autos window says:

    Tables.Count = 1

    stepping into the line:

    Me.GridView1.DataBind()

    the Autos window says

    Me.GridView1.DataSource = {System.Data.DataSet}
    Me.GridView1.Rows.Count 3

    Again, my code found 3 rows in the database based upon the parameter.
    A DataSet is returned to the calling method. That Dataset is linked
    to the Gridview and then DataBind is called. But when DataBind is
    called... nothing happens!

    Any suggestions on how I can get the results in the grid to be
    displayed are greatly appreciated.

    Thanks!
    Adam Sandler, Feb 16, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mharness
    Replies:
    2
    Views:
    469
  2. Kelly Zhu
    Replies:
    1
    Views:
    366
    Cowboy \(Gregory A. Beamer\)
    Nov 19, 2007
  3. Paul
    Replies:
    2
    Views:
    510
  4. sed_y
    Replies:
    0
    Views:
    1,013
    sed_y
    Feb 15, 2012
  5. libsfan01
    Replies:
    5
    Views:
    237
    Jeff North
    Dec 20, 2006
Loading...

Share This Page