Results 1 to 15 of 15

Thread: [RESOLVED][2008] Need held on my Datagrid

  1. #1

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Resolved [RESOLVED][2008] Need held on my Datagrid

    Elow everyone I just want to know how to get the first five row on my datagrid and put in on a textboxes. I just got the First row but how can i get the next succeding row? I have my code upon getting my first row, how about the reamining 5 rows? Here is my code below

    Code:
     myConnection.Open()
    
                myAdapter.Fill(myDataset, "SalesMonitor")
                DataGridView1.DataSource = myDataset.Tables("SalesMonitor")
    
    
                Dim myReader As System.Data.SqlClient.SqlDataReader
                myReader = myCommand.ExecuteReader()
    
                Dim nCnt As Integer
                nCnt = 0
                While myReader.Read()
                    nCnt = nCnt + 1
    
                    If nCnt = 1 Then
                        txtStore1.Text = myReader.GetString(0)
                        lblAPQTY1.Text = myReader.GetDecimal(1)
                        lblAPAMT1.Text = myReader.GetDecimal(2)
                        lblMCQTY1.Text = myReader.GetDecimal(3)
                        lblMCAMT1.Text = myReader.GetDecimal(4)
                        lblATSQTY1.Text = myReader.GetDecimal(5)
                        lblATSAMT1.Text = myReader.GetDecimal(6)
                        lblFURQTY1.Text = myReader.GetDecimal(7)
                        lblFURAMT1.Text = myReader.GetDecimal(8)
                        lblPARTSQTY1.Text = myReader.GetDecimal(9)
                        lblPARTSAMT1.Text = myReader.GetDecimal(10)
                        lblDate1.Text = myReader.GetDateTime(11)
    
    
                    End If
    
                End While
    
                myReader.Close()
                myConnection.Close()

    How can i get the next four succeding row on my datagrid? Could anyone help me pls??? I really need it badly...Thanks in advance guys and have a pleasant morning 2 everyone.
    Last edited by shyguyjeff; May 25th, 2008 at 11:42 PM.

  2. #2

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: [2008] Need held on my Datagrid

    help me this pls...

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Need held on my Datagrid

    Add a RowNumber column to your DataTable and then filter on that. You'll have to create at least one DataView in order to have two different filters.

    If you're using SQL Server is has a ROW_NUMBER function that can add the column to the result set.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: [2008] Need held on my Datagrid

    Could you give me an example of this on how to add rownumber column jm?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Need held on my Datagrid

    Are you using SQL Server 2005? If so I believe it would be like this:
    vb.net Code:
    1. SELECT *, ROW_NUMBER() OVER (ORDER BY ID) AS RowNumber FROM MyTable
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: [2008] Need held on my Datagrid

    i did not use SQL 2005 jm...how about just adding up RowNumber column on my DataTable and then filter it jm?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Need held on my Datagrid

    vb.net Code:
    1. myDataTable.Columns.Add("RowNumber")
    2.  
    3. For rowIndex As Integer = 0 To myDataTable.Rows.Count - 1 Step 1
    4.     myDataTable.Rows(rowIndex)("RowNumber") = rowIndex + 1
    5. Next rowindex
    6.  
    7. Me.BindingSource1.DataSource = myDataTable
    8. Me.BindingSource1.Filter = "RowNumber <= 5"
    9.  
    10. Me.BindingSource2.DataSource = New DataView(myDataTable)
    11. Me.BindingSource2.Filter = "RowNumber > 5"
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: [2008] Need held on my Datagrid

    i receive a blue highlighted text jm saying that BindingSource1 and BindingSource2 is not a member of Form1.

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Need held on my Datagrid

    Quote Originally Posted by shyguyjeff
    i receive a blue highlighted text jm saying that BindingSource1 and BindingSource2 is not a member of Form1.
    Would you like me to add them for you?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: [2008] Need held on my Datagrid

    I could not get what the comments saying jm because Datagrid in vb.net 2003 is so very different on the vb2008 datagrid, there the datagrid can be easily bind but in vb2008 it's not. Sorry if I ask so newbie question.
    Last edited by shyguyjeff; May 23rd, 2008 at 03:37 AM.

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Need held on my Datagrid

    Binding data to a DataGridView in VB 2008 is no more difficult than binding data to a DataGrid in VB.NET 2003. They both have a DataSource property that you assign your list to. That's it. In VB 2008 it is generally preferable to use a BindingSource when data-binding as it makes various tasks easier. It also has a DataSource property. You bind your list to the BindingSource and your BindingSource to the grid. Two steps instead of one but they both involve simply setting a DataSource property.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: [2008] Need held on my Datagrid

    ahhhh...okies jm...i just misunderstood the comments jm...now i already...Again a million thanks to jm..Have a nice day and God Bless...

  13. #13

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: [2008] Need held on my Datagrid

    I forgot to ask jm...How can I call the rows and put it on the textbox? on my first post I already got the First row and successfully put it on the textbox my problem is that on the 2 up to fifth row how can I got it?

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Need held on my Datagrid

    You should be binding the data, which is why I used a BindingSource in my example. Again, it's exactly the same as in .NET 1.x: you bind the list to the controls via the DataBindings collection.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  15. #15

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: [2008] Need held on my Datagrid

    Quote Originally Posted by jmcilhinney
    You should be binding the data, which is why I used a BindingSource in my example. Again, it's exactly the same as in .NET 1.x: you bind the list to the controls via the DataBindings collection.
    Thanks jm...But my problem is that don't know yet how to bind Data using Databindings. I used listview last on my vb.net 2003 that why im not yet too familiar with the datagridview now. Could you give at least one example jm like for example on my datagridview, there are five columns then 5 rows this is the following format.


    Storename MC AP Total
    Store1 1000 2000 3000
    Store2 2000 2000 4000
    Store3 1500 2000 3500
    Store4 3000 2000 5000
    Store5 2000 2500 4500

    I want to get it jm and put it on my textbox. Like for example I want to get the textbox1.text = row(1) column(1),textbox2.text = row(1) column(2) Is it possible jm?Thanks again jm..Have a nice day..God Bless...
    Last edited by shyguyjeff; May 25th, 2008 at 09:01 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width