Data in dataset but not displaying in gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kjewell23
    New Member
    • Sep 2007
    • 49

    Data in dataset but not displaying in gridview

    Hello, I'm new to this asp.net 2.0 I need help??
    My database is coming from AS400 which uses odbc Commands. i have data in the dataset but nothing showing in my gridview. However the data does show on the page. Could you please see what I'm doing wrong.

    My code is down below
    [code=vbnet]
    Protected Sub btnSubmit_Click (ByVal sender As Object, ByVal e As System.EventArg s) Handles btnSubmit.Click


    Dim myconnection As OdbcConnection
    Dim myCommand As OdbcDataAdapter
    Dim mydataset As New DataSet
    Dim gvResults As DataTable
    Dim loop1 As Integer
    Dim numrows As Integer
    Dim mysql As String
    Dim Order As Integer
    Order = CInt(txtOrderNu mber.Text)


    mysql = "select line#, ordno, quano, quana, quans, c2rdt, unitm, prdno, actsp from rmsfiles2.obcop 200 where ordno = " & Order
    myconnection = New OdbcConnection( "DRIVER=Cli ent Access ODBC Driver (32-bit);UID=ODBC;P WD=XXXXX;System =xxx.xxx.xxx.xx x")

    myCommand = New OdbcDataAdapter (mysql, myconnection)

    myCommand.Fill( mydataset, "OBCOP200")

    gvResults = New DataTable
    gvResults = mydataset.Table s(0)

    numrows = gvResults.Rows. Count

    If numrows = 0 Then
    txtOrderNumber. Text = "Order#" & txtOrderNumber. Text & " invalid order number"

    Else
    txtOrderNumber. Text = ""

    For loop1 = 0 To numrows - 1

    Response.Write( Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "ordno")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "quano")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "quana")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "quans")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "c2rdt")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "unitm")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "prdno")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "actsp")) & " <br>")


    Next loop1
    gridview1.DataB ind()
    End If

    gridview1.DataS ource = mydataset.Table s("OBCOP200").D efaultView
    gridview1.DataB ind()
    gridview1.Visib le = True[/code]
    Last edited by Frinavale; Sep 11 '07, 06:03 PM. Reason: Added [code] tags to make more legible...removed IP address to Database
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Hi Kjewell23,

    I've moved your question to the .NET Forum.
    The .NET Articles section is reserved for "how-tos" and other helpful tips and is not meant for questions. In the future please post your questions in the .NET Forum (Blue menu at top: Forums -> .NET).

    Also, it is not a good idea to post your IP's with your code.
    I've edited your post to remove the IP.

    Thanks!

    -Frinny

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by kjewell23
      Hello, I'm new to this asp.net 2.0 I need help??
      My database is coming from AS400 which uses odbc Commands. i have data in the dataset but nothing showing in my gridview. However the data does show on the page. Could you please see what I'm doing wrong. ....
      What do you mean that it shows up on the page?

      Comment

      • kjewell23
        New Member
        • Sep 2007
        • 49

        #4
        Originally posted by Frinavale
        What do you mean that it shows up on the page?
        The data shows up on the top of the page but it pushes everything down like the title of the page, textbox, and button. Here i show you want I mean

        Down below

        600452 1.000 0 1.000 9/25/2006 EA 06759055 30.450 ( this is the data)


        (title)Order Detail Inquiry

        Order Number(label) textbox here (submit button here)

        Comment

        • nanku71
          New Member
          • Sep 2007
          • 4

          #5
          Hi jewell,,

          I would suggest to remove part of the code that i am pasting here and replace with what i am giving here.

          Remove this :
          [code=vbnet]

          #
          If numrows = 0 Then
          #
          txtOrderNumber. Text = "Order#" & txtOrderNumber. Text & " invalid order number"
          #

          #
          Else
          #
          txtOrderNumber. Text = ""
          #

          #
          For loop1 = 0 To numrows - 1
          #

          #
          Response.Write( Server.HtmlEnco de(gvResults.Ro ws(lo op1).Item("ordn o")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "quano")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "quana")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "quans")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "c2rdt")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "unitm")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "prdno")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "actsp")) & " <br>")
          #

          #

          #
          Next loop1
          #
          gridview1.DataB ind()
          #
          End If
          #

          #
          gridview1.DataS ource = mydataset.Table s("OBCOP200").D efaultView
          [/code]

          Replace it with.
          [code=vbnet]
          gridview1.DataS ource = mydataset.Table s("OBCOP200")
          [/code]
          and let me know how it went.

          thanks

          Samir

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Originally posted by kjewell23
            The data shows up on the top of the page but it pushes everything down like the title of the page, textbox, and button. Here i show you want I mean

            Down below

            600452 1.000 0 1.000 9/25/2006 EA 06759055 30.450 ( this is the data)


            (title)Order Detail Inquiry

            Order Number(label) textbox here (submit button here)
            Oh ok, that's because of the Response.Write that you have there...sorry for some reason I skipped over that whole bit of code...taking a closer look at your code now.

            Try removing the gridview1.DataB ind() from Here:
            [code=vbnet]

            If numrows = 0 Then
            txtOrderNumber. Text = "Order#" & txtOrderNumber. Text & " invalid order number"

            Else
            txtOrderNumber. Text = ""

            For loop1 = 0 To numrows - 1

            Response.Write( Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "ordno")) & " " & Server.HtmlEnco de(g gridview1.DataS ource = mydataset.Table s("OBCOP200").D efaultView
            gridview1.DataB ind()
            gridview1.Visib le = True


            vResults.Rows(l oop1).Item("qua no")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "quana")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "quans")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "c2rdt")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "unitm")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "prdno")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "actsp")) & " <br>")


            Next loop1
            'remove ------> gridview1.DataB ind()
            End If[/code]


            And try making this change as well:
            [code=vbnet]
            gridview1.DataS ource = mydataset
            gridview1.DataB ind()
            gridview1.Visib le = True
            [/code]

            It may be that it can't find
            [code=vbnet] gridview1.DataS ource = mydataset.Table s("OBCOP200").D efaultView[/code]

            -Frinny

            Comment

            • kjewell23
              New Member
              • Sep 2007
              • 49

              #7
              Ok that didn't work It shows nothing.
              Originally posted by nanku71
              Hi jewell,,

              I would suggest to remove part of the code that i am pasting here and replace with what i am giving here.

              Remove this :

              #
              If numrows = 0 Then
              #
              txtOrderNumber. Text = "Order#" & txtOrderNumber. Text & " invalid order number"
              #

              #
              Else
              #
              txtOrderNumber. Text = ""
              #

              #
              For loop1 = 0 To numrows - 1
              #

              #
              Response.Write( Server.HtmlEnco de(gvResults.Ro ws(lo op1).Item("ordn o")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "quano")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "quana")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "quans")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "c2rdt")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "unitm")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "prdno")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "actsp")) & " <br>")
              #

              #

              #
              Next loop1
              #
              gridview1.DataB ind()
              #
              End If
              #

              #
              gridview1.DataS ource = mydataset.Table s("OBCOP200").D efaultView


              Replace it with.

              gridview1.DataS ource = mydataset.Table s("OBCOP200")

              and let me know how it went.

              thanks

              Samir

              Comment

              • kjewell23
                New Member
                • Sep 2007
                • 49

                #8
                So just take out the gridview1.datab ind() in the next loop1 section


                Originally posted by Frinavale
                Oh ok, that's because of the Response.Write that you have there...sorry for some reason I skipped over that whole bit of code...taking a closer look at your code now.

                Try removing the gridview1.DataB ind() from Here:
                [code=vbnet]

                If numrows = 0 Then
                txtOrderNumber. Text = "Order#" & txtOrderNumber. Text & " invalid order number"

                Else
                txtOrderNumber. Text = ""

                For loop1 = 0 To numrows - 1

                Response.Write( Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "ordno")) & " " & Server.HtmlEnco de(g gridview1.DataS ource = mydataset.Table s("OBCOP200").D efaultView
                gridview1.DataB ind()
                gridview1.Visib le = True


                vResults.Rows(l oop1).Item("qua no")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "quana")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "quans")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "c2rdt")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "unitm")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "prdno")) & " " & Server.HtmlEnco de(gvResults.Ro ws(loop1).Item( "actsp")) & " <br>")


                Next loop1
                'remove ------> gridview1.DataB ind()
                End If[/code]


                And try making this change as well:
                [code=vbnet]
                gridview1.DataS ource = mydataset
                gridview1.DataB ind()
                gridview1.Visib le = True
                [/code]

                It may be that it can't find
                [code=vbnet] gridview1.DataS ource = mydataset.Table s("OBCOP200").D efaultView[/code]

                -Frinny

                Comment

                • Frinavale
                  Recognized Expert Expert
                  • Oct 2006
                  • 9749

                  #9
                  Originally posted by kjewell23
                  So just take out the gridview1.datab ind() in the next loop1 section
                  Yes and take out the .Tables("..."). DefaultView from:
                  [code=vbnet]
                  gridview1.DataS ource = mydataset.Table s("OBCOP200").D efaultView
                  [/code]

                  I have a feeling you're looking up a table in your data set that doesn't exist...

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    Using Response.Write( ) is discouraged if you have controls on the page as using it can cause unknown/undesired results.
                    You should use an ASP:Label or ASP:Panel and write the text inside those instead.

                    Also, there a few things that could cause no data to be displayed:
                    • Configurable display options for gridview are set to hide data
                    • Cycling through the DataTable with that lookp is marking the data "read" and the gridview sees that (very unlikely)
                    • Nameing the DataTable with a TableName is causing some confusion and the gridview is only getting to look at an empty table because of it.
                    • Also, I would have to check, but try taking out the ".DefaultVi ew", since gridviews want a table not a view. (I always just use the Table)


                    You can use the DataAdapter to populate a DataTable directly rather then a DataSet if you wanted.

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #11
                      Originally posted by Plater
                      Using Response.Write( ) is discouraged if you have controls on the page as using it can cause unknown/undesired results.
                      You should use an ASP:Label or ASP:Panel and write the text inside those instead.

                      Also, there a few things that could cause no data to be displayed:
                      • Configurable display options for gridview are set to hide data
                      • Cycling through the DataTable with that lookp is marking the data "read" and the gridview sees that (very unlikely)
                      • Nameing the DataTable with a TableName is causing some confusion and the gridview is only getting to look at an empty table because of it.
                      • Also, I would have to check, but try taking out the ".DefaultVi ew", since gridviews want a table not a view. (I always just use the Table)


                      You can use the DataAdapter to populate a DataTable directly rather then a DataSet if you wanted.
                      I thought that the Response.Write bit was for debugging purposes....
                      Am I wrong here???

                      Comment

                      • kjewell23
                        New Member
                        • Sep 2007
                        • 49

                        #12
                        i did that and it still displays but not in gridview. It shows that I have three rows in the part where if numrows and on down . When I debug it it shows system. dataset where the fill command is and then it shows mydataset.Table s = {System.Data.Da taTableCollecti on} at gvResults = (where the datatable is)
                        then it has the number of rows in if then and then it has the number that i typed inside the text box also in the else then it through the loop 23 times before displaying it. and then finally it shows at gridview1.DataS ource = Nothing
                        after the if statements ends when its highlighted then after highlightended is gone is shows mydataset = {System.Data.Da taSet}

                        so does that mean anything to you

                        Originally posted by Frinavale
                        Yes and take out the .Tables("..."). DefaultView from:
                        [code=vbnet]
                        gridview1.DataS ource = mydataset.Table s("OBCOP200").D efaultView
                        [/code]

                        I have a feeling you're looking up a table in your data set that doesn't exist...

                        Comment

                        • kjewell23
                          New Member
                          • Sep 2007
                          • 49

                          #13
                          the response write is for debugging but if I take that out nothing shows up

                          Originally posted by Frinavale
                          I thought that the Response.Write bit was for debugging purposes....
                          Am I wrong here???

                          Comment

                          • kjewell23
                            New Member
                            • Sep 2007
                            • 49

                            #14
                            Wel their are certain numbers that has alot of pages so I was going to do sorting and paging. Can a panel do that?

                            Originally posted by Frinavale
                            I thought that the Response.Write bit was for debugging purposes....
                            Am I wrong here???

                            Comment

                            • Plater
                              Recognized Expert Expert
                              • Apr 2007
                              • 7872

                              #15
                              From what I've read, Response.Write( ) just injects whatever you put into the current section of the buffer. Which could be inside one of your html elements.
                              I thought it was supposed to work similar to javascripts' Document.Write( ), but I've ehard of it doing funny things with the sending buffer from people.

                              Originally posted by Frinavale
                              I thought that the Response.Write bit was for debugging purposes....
                              Am I wrong here???

                              Comment

                              Working...