Data in dataset but not displaying in gridview

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

    #31
    It still doesn't display anything. Here is all my code is aspx.vb part
    [code=vbnet]
    Imports System
    Imports System.Data
    Imports System.Data.Sql Client
    Imports System.Data.Odb c
    Imports System.Data.Dat aSet
    Imports System.Data.Dat aTableCollectio n
    Imports IBM.Data.DB2.iS eries
    Partial Class Parts_Inquiries _OrderDetailInq uiry
    Inherits System.Web.UI.P age
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load


    'Define variable to pass parm from calling page.
    Dim OrderNumber As String
    OrderNumber = Request.QuerySt ring("ordno")

    'If part number passed in plug it into text box
    If txtOrderNumber. Text = "" And OrderNumber > "" Then
    txtOrderNumber. Text = OrderNumber
    End If

    'Conditionally return to menu or previous page depending if parm passed in

    exitHyperLink.T ext = " Prev"
    exitHyperLink.N avigateUrl = "~/Parts/Inquiries/OrderInquiry.as px" & txtOrderNumber. Text & ""

    TrackingHyperLi nk.Text = "Tracking"
    TrackingHyperLi nk.NavigateUrl = "~/parts/inquiries/TrackingInquiry .aspx?ordno=" & txtOrderNumber. Text & ""

    exitHyperLink.T ext = "Exit"
    exitHyperLink.N avigateUrl = "~/parts/inquiries/EngineeringInqu iryMenu.aspx"


    End Sub

    Protected Sub btnSubmit_Click (ByVal sender As Object, ByVal e As System.EventArg s) Handles btnSubmit.Click

    Dim connectionStrin g = "DRIVER=Cli ent Access ODBC Driver (32-bit);UID=ODBC;P WD=xxxxxxxxxx;S ystem=xxx.xxx.x xx.xxx"


    Dim myconnection As OdbcConnection
    Dim myCommand As OdbcDataAdapter
    Dim mydataset As New DataSet
    Dim sql As String
    Dim Order As Integer
    Order = CInt(txtOrderNu mber.Text)
    sql = "select line#, ordno, quano, quana, quans, c2rdt, unitm, prdno, actsp from rmsfiles2.obcop 200 where ordno = " & Order
    Try

    myconnection = New OdbcConnection( "DRIVER=Cli ent Access ODBC Driver (32-bit);UID=ODBC;P WD=xxxxxxxxx;Sy stem=xxx.xxx.xx x.xxx")

    myCommand = New OdbcDataAdapter (sql, myconnection)

    myCommand.Fill( mydataset)
    Catch ex As Exception
    txtOrderNumber. Text = "invalid order number"

    End Try

    gridview1.DataS ource = mydataset
    gridview1.DataB ind()
    gridview1.Visib le = True



    End Sub

    Function GetData(ByVal mysql As String, ByVal myOrderNumber As Integer) As DataSet

    Dim connectionStrin g = "DRIVER=Cli ent Access ODBC Driver (32-bit);UID=ODBC;P WD=xxxxxxxxxxx; System=xxx.xxx. xxx.xxx"


    Dim myconnection As OdbcConnection
    Dim myCommand As OdbcDataAdapter
    Dim mydataset As New DataSet

    Dim sql As String
    Dim Order As Integer
    Order = CInt(txtOrderNu mber.Text)
    sql = "select line#, ordno, quano, quana, quans, c2rdt, unitm, prdno, actsp from rmsfiles2.obcop 200 where ordno = " & Order
    Try

    myconnection = New OdbcConnection( "DRIVER=Cli ent Access ODBC Driver (32-bit);UID=ODBC;P WD=xxxxxx;Syste m=xxx.xxx.xxx.x xx")

    myCommand = New OdbcDataAdapter (sql, myconnection)

    myCommand.Fill( mydataset)
    Catch ex As Exception
    txtOrderNumber. Text = "invalid order number"

    End Try

    Return mydataset
    End Function


    End Class

    [/code]
    Last edited by Frinavale; Sep 12 '07, 02:12 PM. Reason: Removing quote so that post will display

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #32
      I've cleaned up your code so that its easier to follow.
      Try this and tell me if it works...if it doesn't repost your exact code and we'll have another look.

      [code=vbnet]
      Imports System
      Imports System.Data
      Imports System.Data.Sql Client
      Imports System.Data.Odb c
      Imports System.Data.Dat aSet
      Imports System.Data.Dat aTableCollectio n
      Imports IBM.Data.DB2.iS eries
      Partial Class Parts_Inquiries _OrderDetailInq uiry
      Inherits System.Web.UI.P age
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load


      'Define variable to pass parm from calling page.
      Dim OrderNumber As String
      OrderNumber = Request.QuerySt ring("ordno")

      'If part number passed in plug it into text box
      If txtOrderNumber. Text = "" And OrderNumber > "" Then
      txtOrderNumber. Text = OrderNumber
      End If

      'Conditionally return to menu or previous page depending if parm passed in

      exitHyperLink.T ext = " Prev"
      exitHyperLink.N avigateUrl = "~/Parts/Inquiries/OrderInquiry.as px" & txtOrderNumber. Text & ""

      TrackingHyperLi nk.Text = "Tracking"
      TrackingHyperLi nk.NavigateUrl = "~/parts/inquiries/TrackingInquiry .aspx?ordno=" & txtOrderNumber. Text & ""

      exitHyperLink.T ext = "Exit"
      exitHyperLink.N avigateUrl = "~/parts/inquiries/EngineeringInqu iryMenu.aspx"


      End Sub

      Protected Sub btnSubmit_Click (ByVal sender As Object, ByVal e As System.EventArg s) Handles btnSubmit.Click

      'Dim connectionStrin g = "DRIVER=Cli ent Access ODBC Driver (32-bit);UID=ODBC;P WD=xxxxxxxxxx;S ystem=xxx.xxx.x xx.xxx"


      'Dim myconnection As OdbcConnection
      ' Dim myCommand As OdbcDataAdapter
      'Dim mydataset As New DataSet
      'Dim sql As String
      Dim Order As Integer
      ' Order = CInt(txtOrderNu mber.Text)

      '************** ******New Code*********** **************
      'The following makes sure that the value from the
      'txtOrderNumber is actually a number...it will handles the
      'casting error
      Try
      Order = Integer.Parse(t xtOrderNumber.T xt)
      Catch e As Exception
      Order = 0
      txtOrderNumber. Text= "Please Supply A Valid Number"
      End Try
      '************** *************** *************** **********


      'The following has been commented out as it is done in your GetData Function

      'sql = "select line#, ordno, quano, quana, quans, c2rdt, unitm, prdno, actsp from rmsfiles2.obcop 200 where ordno = " & Order
      'Try

      'myconnection = New OdbcConnection( "DRIVER=Cli ent Access ODBC Driver (32-bit);UID=ODBC;P WD=xxxxxxxxx;Sy stem=xxx.xxx.xx x.xxx")

      'myCommand = New OdbcDataAdapter (sql, myconnection)

      'myCommand.Fill (mydataset)
      'Catch ex As Exception
      'txtOrderNumber .Text = "invalid order number"

      ' End Try

      '************** ******New Code*********** **************
      Dim ds As DataSet = GetData(Order)
      If (ds.Tables.Coun t > 0) Then
      'gridview1.Data Source = mydataset
      gridview1.DataS ource = ds
      gridview1.DataB ind()
      gridview1.Visib le = True
      Else
      txtOrderNumber. Text="Unable to retrieve data"
      End If
      '************** *************** *************** ************

      End Sub

      'Function GetData(ByVal mysql As String, ByVal myOrderNumber As Integer) As DataSet
      'Redefined how your GetData function works to better suit your specific problem.....

      Function GetData(ByVal myOrderNumber As Integer) As DataSet
      'Your Connection String should be stored in your web.config file.
      'It should be stored in the <connectionStri ngs> section......
      'We can get to that later if you would like
      Dim connectionStrin g = "DRIVER=Cli ent Access ODBC Driver (32-bit);UID=ODBC;P WD=xxxxxxxxxxx; System=xxx.xxx. xxx.xxx"


      Dim myconnection As OdbcConnection
      Dim myCommand As OdbcDataAdapter
      Dim mydataset As New DataSet

      Dim sql As String
      'Order has been passed into this function and so this isn't needed
      ' Dim Order As Integer
      'Order = CInt(txtOrderNu mber.Text)
      'sql = "select line#, ordno, quano, quana, quans, c2rdt, unitm, prdno, actsp from rmsfiles2.obcop 200 where ordno = " & Order
      sql = "select line#, ordno, quano, quana, quans, c2rdt, unitm, prdno, actsp from rmsfiles2.obcop 200 where ordno = " & Order.ToString( )
      'Please note the Order.ToString( )....
      Try

      myconnection = New OdbcConnection( connectionStrin g )

      myCommand = New OdbcDataAdapter (sql, myconnection)

      myCommand.Fill( mydataset)
      Catch ex As Exception
      txtOrderNumber. Text = "Database Error: Unable to fill DataSet"

      End Try

      Return mydataset
      End Function


      End Class

      [/code]

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #33
        Oh I see an error...you're not using the myOrderNumber parameter in your search......The code should be:

        [code=vbnet]
        Function GetData(ByVal myOrderNumber As Integer) As DataSet

        Dim connectionStrin g = "DRIVER=Cli ent Access ODBC Driver (32-bit);UID=ODBC;P WD=xxxxxxxx;Sys tem=xxx.xxx.xxx .xxx"


        Dim myconnection As OdbcConnection
        Dim myCommand As OdbcDataAdapter
        Dim mydataset As New DataSet
        Dim sql As String
        'Dim Order As Integer
        'Order = CInt(txtOrderNu mber.Text)
        '*********Chang e the following Line*********** ********
        'sql = "select line#, ordno, quano, quana, quans, c2rdt, unitm, prdno, actsp from rmsfiles2.obcop 200 where ordno = " & Order.ToString( )

        '**********To this .........****** ***********
        sql = "select line#, ordno, quano, quana, quans, c2rdt, unitm, prdno, actsp from rmsfiles2.obcop 200 where ordno = " & myOrderNumber .ToString()
        Try

        myconnection = New OdbcConnection( connectionStrin g)
        myCommand = New OdbcDataAdapter (sql, myconnection)
        myCommand.Fill( mydataset)
        Catch ex As Exception
        txtOrderNumber. Text = "Database Error:Unable to fill Dataset"

        End Try

        Return mydataset
        End Function
        [/code]

        Comment

        • kjewell23
          New Member
          • Sep 2007
          • 49

          #34
          Guess what it still don't work here is my code again

          [code=vbnet]

          Imports System
          Imports System.Data
          Imports System.Data.Sql Client
          Imports System.Data.Odb c
          Imports System.Data.Dat aSet
          Imports System.Data.Dat aTableCollectio n
          Imports IBM.Data.DB2.iS eries
          Partial Class Parts_Inquiries _OrderDetailInq uiry
          Inherits System.Web.UI.P age
          Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load


          'Define variable to pass parm from calling page.
          Dim OrderNumber As String
          OrderNumber = Request.QuerySt ring("ordno")

          'If part number passed in plug it into text box
          If txtOrderNumber. Text = "" And OrderNumber > "" Then
          txtOrderNumber. Text = OrderNumber
          End If

          'Conditionally return to menu or previous page depending if parm passed in

          exitHyperLink.T ext = " Prev"
          exitHyperLink.N avigateUrl = "~/Parts/Inquiries/OrderInquiry.as px" & txtOrderNumber. Text & ""

          TrackingHyperLi nk.Text = "Tracking"
          TrackingHyperLi nk.NavigateUrl = "~/parts/inquiries/TrackingInquiry .aspx?ordno=" & txtOrderNumber. Text & ""

          exitHyperLink.T ext = "Exit"
          exitHyperLink.N avigateUrl = "~/parts/inquiries/EngineeringInqu iryMenu.aspx"


          End Sub

          Protected Sub btnSubmit_Click (ByVal sender As Object, ByVal e As System.EventArg s) Handles btnSubmit.Click

          Dim Order As Integer

          Try
          Order = Integer.Parse(t xtOrderNumber.T ext)

          Catch ex As Exception
          Order = 0
          txtOrderNumber. Text = "Please supply a valid number"
          'End Catch

          End Try
          Dim mydataset As DataSet = GetData(Order)
          If (mydataset.Tabl es.Count > 0) Then
          gridview1.DataS ource = mydataset
          gridview1.DataB ind()
          gridview1.Visib le = True
          Else
          txtOrderNumber. Text = "Unable to retrieve data"
          End If



          End Sub
          Function GetData(ByVal myOrderNumber As Integer) As DataSet

          Dim connectionStrin g = "DRIVER=Cli ent Access ODBC Driver (32-bit);UID=ODBC;P WD=XXXXXX;Syste m=XXX.XXX.XXX.X XX"


          Dim myconnection As OdbcConnection
          Dim myCommand As OdbcDataAdapter
          Dim mydataset As New DataSet

          Dim sql As String
          'Dim myOrderNumber As Integer

          sql = "select line#, ordno, quano, quana, quans, c2rdt, unitm, prdno, actsp from rmsfiles2.obcop 200 where ordno = " & myOrderNumber.T oString()

          Try

          myconnection = New OdbcConnection( connectionStrin g)
          myCommand = New OdbcDataAdapter (sql, myconnection)

          myCommand.Fill( mydataset)
          Catch ex As Exception
          txtOrderNumber. Text = "Database Error:Unable to fill Dataset"

          End Try

          Return mydataset
          End Function

          End Class[/code]
          Last edited by Frinavale; Sep 12 '07, 06:17 PM. Reason: Added [code] tags and removed IP and Password

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #35
            Originally posted by kjewell23
            Guess what it still don't work here is my code again
            Are you getting any messages in your txtOrderNumber text box?

            Could you please start using [ code] tags?

            All you do is type: [ code=vbnet] then paste your code and then type [ /code]
            (Please note that I left a space between the [ and the word "code" (or /code)..you have to remove the space to make the code tags work properly).

            That'll save me from editing your posts :)
            Also there is a comment in your code that contains your IP and Password still....you might want to fix this.

            I'm going to look into reasons why this isn't working for you...get back to me about the messages :)

            -Frinny

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #36
              I keep wondering if it has something to do with your DataSet.
              Why don't we try using a DataView again?

              I've used the following GetData function with my own GridView and it works fine...this should work for you too!

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

              Dim Order As Integer

              Try
              Order = Integer.Parse(t xtOrderNumber.T ext)

              Catch ex As Exception
              Order = 0
              txtOrderNumber. Text = "Please supply a valid number"
              'End Catch

              End Try
              'For now comment this out....
              ' Dim mydataset As DataSet = GetData(Order)
              ' If (mydataset.Tabl es.Count > 0) Then
              ' gridview1.DataS ource = mydataset
              gridview1.DataS ource =GetData(Order)
              gridview1.DataB ind()
              gridview1.Visib le = True
              ' Else
              ' txtOrderNumber. Text = "Unable to retrieve data"
              ' End If
              End Sub

              '************Al so comment out your current GetData Function and
              ' Copy in the following code.....
              Function GetData(ByVal myOrderNumber As Integer) As Data.DataView
              Dim dr As Data.DataRow
              Dim dt As New Data.DataTable

              dt.Columns.Add( New Data.DataColumn ("First Name", GetType(String) ))
              dt.Columns.Add( New Data.DataColumn ("Last Name", GetType(String) ))

              dr = dt.NewRow
              dr("First Name") = "first row, first name"
              dr("Last Name") = "first row, last name"

              dt.Rows.Add(dr)

              dr = dt.NewRow
              dr("First Name") = "second row, first name"
              dr("Last Name") = "second row, last name"

              dt.Rows.Add(dr)

              Dim dv As New Data.DataView(d t)
              Return dv
              End Function
              [/code]

              Comment

              • kjewell23
                New Member
                • Sep 2007
                • 49

                #37
                Ok thanks. The number that I typed in the textbox stays their after I hit the submit button. No messages or data is nowhere on that page.

                Comment

                • Frinavale
                  Recognized Expert Expert
                  • Oct 2006
                  • 9749

                  #38
                  Originally posted by kjewell23
                  Ok thanks. The number that I typed in the textbox stays their after I hit the submit button. No messages or data is nowhere on that page.

                  Strange.
                  I would have expected it to have changed.
                  Using a Label to display error messages instead of your text box that you use for your input is a good idea :)

                  Did you try that code with the DataView yet?

                  Comment

                  • kjewell23
                    New Member
                    • Sep 2007
                    • 49

                    #39
                    So should I replace first name with ordno(factory order) and last name with quano(quantity)

                    [code=vbnet]

                    Function GetData(ByVal myOrderNumber As Integer) As Data.DataView
                    Dim dr As Data.DataRow
                    Dim dt As New Data.DataTable

                    dt.Columns.Add( New Data.DataColumn ("First Name", GetType(String) ))
                    dt.Columns.Add( New Data.DataColumn ("Last Name", GetType(String) ))

                    dr = dt.NewRow
                    dr("First Name") = "first row, first name"
                    dr("Last Name") = "first row, last name"

                    dt.Rows.Add(dr)

                    dr = dt.NewRow
                    dr("First Name") = "second row, first name"
                    dr("Last Name") = "second row, last name"

                    dt.Rows.Add(dr)

                    Dim dv As New Data.DataView(d t)
                    Return dv
                    End Function
                    [/code]

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #40
                      Originally posted by kjewell23
                      So should I replace first name with ordno(factory order) and last name with quano(quantity)

                      [code=vbnet]

                      Function GetData(ByVal myOrderNumber As Integer) As Data.DataView
                      Dim dr As Data.DataRow
                      Dim dt As New Data.DataTable

                      dt.Columns.Add( New Data.DataColumn ("First Name", GetType(String) ))
                      dt.Columns.Add( New Data.DataColumn ("Last Name", GetType(String) ))

                      dr = dt.NewRow
                      dr("First Name") = "first row, first name"
                      dr("Last Name") = "first row, last name"

                      dt.Rows.Add(dr)

                      dr = dt.NewRow
                      dr("First Name") = "second row, first name"
                      dr("Last Name") = "second row, last name"

                      dt.Rows.Add(dr)

                      Dim dv As New Data.DataView(d t)
                      Return dv
                      End Function
                      [/code]
                      Just see if this works first...if you get something to appear then try entering other things :)

                      Comment

                      • kjewell23
                        New Member
                        • Sep 2007
                        • 49

                        #41
                        I don't get anything still no data

                        Comment

                        • kjewell23
                          New Member
                          • Sep 2007
                          • 49

                          #42
                          How would I use a label for error messages and where do I put the code at
                          Originally posted by Frinavale
                          Strange.
                          I would have expected it to have changed.
                          Using a Label to display error messages instead of your text box that you use for your input is a good idea :)

                          Did you try that code with the DataView yet?

                          Comment

                          • Frinavale
                            Recognized Expert Expert
                            • Oct 2006
                            • 9749

                            #43
                            Originally posted by kjewell23
                            How would I use a label for error messages and where do I put the code at
                            In the Desgin View for your ASPX page:
                            • Drag a Label object onto it
                            • Click on the Label and in its properties set it's a name identifying it (eg: lbl_error)


                            Then when ever you want to display a message in the label, you set it the same way you do your TextBox...

                            Eg.
                            [code=vbnet]
                            lbl_error.Text= "this is my message"
                            [/code]
                            Just remember to clear the label every time a page request is made (in your page load set it's text to "") so that you aren't redisplaying old error messages.

                            Could you please post the ASP code for your GridView for me.
                            You will find this code in the Source View for you ASPX page...
                            (post it in [code =html] code tags).

                            I'm looking for something like the following:
                            [code=html]
                            <asp:GridView ID="myGridView " runat="server" CellPadding="4" ForeColor="#333 333">
                            <FooterStyle BackColor="#5D7 B9D" Font-Bold="True" ForeColor="Whit e" />
                            <RowStyle BackColor="#F7F 6F3" ForeColor="#333 333" BorderColor="Bl ack" BorderStyle="So lid" BorderWidth="1p x" />
                            <EditRowStyle BackColor="#999 999" />
                            <SelectedRowSty le BackColor="#E2D ED6" Font-Bold="True" ForeColor="#333 333" />
                            <PagerStyle BackColor="#284 775" ForeColor="Whit e" HorizontalAlign ="Center" />
                            <HeaderStyle BackColor="#5D7 B9D" Font-Bold="True" ForeColor="Whit e" />
                            <AlternatingRow Style BackColor="Whit e" ForeColor="#284 775" BorderColor="Bl ack" BorderStyle="So lid" BorderWidth="1p x" />
                            <Columns>
                            </Columns>
                            </asp:GridView>[/code]

                            Comment

                            • kjewell23
                              New Member
                              • Sep 2007
                              • 49

                              #44
                              data in dataset but not displaying in gridview

                              I did this in page load lbl_error.Text = ""
                              and submit. Is this right lbl_error.Text = "Please supply a valid number"

                              This of course is in the aspx page
                              [code=html]
                              <asp:GridView ID="gridview1" runat="server" CellPadding="3" ForeColor="Blac k" GridLines="Vert ical" BackColor="Whit e" BorderColor="#9 99999" BorderStyle="So lid" BorderWidth="1p x" Width="275px" AllowPaging="Tr ue" AutoGenerateCol umns="False" AllowSorting="T rue" >
                              <SelectedRowSty le BackColor="#000 099" Font-Bold="True" ForeColor="Whit e" />
                              <PagerStyle BackColor="#999 999" ForeColor="Blac k" HorizontalAlign ="Center" />
                              <HeaderStyle BackColor="Blac k" Font-Bold="True" ForeColor="Whit e" />
                              <AlternatingRow Style BackColor="#CCC CCC" />
                              </asp:GridView>
                              </asp:GridView>[/code]
                              Last edited by kjewell23; Sep 12 '07, 08:58 PM. Reason: forgot something

                              Comment

                              • Frinavale
                                Recognized Expert Expert
                                • Oct 2006
                                • 9749

                                #45
                                Originally posted by kjewell23
                                I did this in page load lbl_error.Text = ""
                                and submit. Is this right lbl_error.Text = "Please supply a valid number"

                                This of course is in the aspx page...
                                If you don't supply a number in the txtOrderNumber TextBox and you click the button, then yes you should be getting this message.

                                The reason you are getting this is because of this section of code:

                                [code=vbnet]
                                Protected Sub btnSubmit_Click (ByVal sender As Object, ByVal e As System.EventArg s) Handles btnSubmit.Click
                                '........
                                '........
                                Try
                                Order = Integer.Parse(t xtOrderNumber.T ext)
                                Catch ex As Exception
                                Order = 0
                                'I'm assuming that your label is being used here now...
                                'txtOrderNumber .Text = "Please supply a valid number"

                                End Try
                                '........
                                '........
                                [/code]

                                In this section of code, you are attempting to convert the value found in the txtOrderNumber TextBox into an Integer value. If there is a problem, then the value in the txtOrderNumber Text box was not a number and an exception is thrown. The exception is caught in the Catch portion and the "Please supply a number" message is displayed.

                                Comment

                                Working...