Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Counting Values in a Datagrid Vb.net asp.net visual studios 2005

Counting Values in a Datagrid Vb.net asp.net visual studios 2005

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-nettutorial
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MeterMan
    wrote on last edited by
    #1

    For some reason I can't seem to get DataRow to come up in intellatype or whatever its called. What I have is a datagrid with a bound datasourse of Mydata. I want to count the values for the expense field and put them into a text box at the bottom of the page. My assumption was I could do something like the following. Dim MyDataRow as DataRow Dim MySum as integer foreach (MyDataRow in Mydata.Expense[5].rows) MySum = MySum + convert.ToInt32(MyDataRow["Expense"]) end for Pardon my coding cause i'm very new to vb. Any help would be greatful or a working example that uses vb.net asp.net with visual studios 2005 that explains this would be wonderful. I manually coded my dataset but used the designer to make the datagrid not sure if thats a problem or not. Win32newb "Programming is like Sex, make a mistake and you end up providing support for a long time"

    T I 2 Replies Last reply
    0
    • M MeterMan

      For some reason I can't seem to get DataRow to come up in intellatype or whatever its called. What I have is a datagrid with a bound datasourse of Mydata. I want to count the values for the expense field and put them into a text box at the bottom of the page. My assumption was I could do something like the following. Dim MyDataRow as DataRow Dim MySum as integer foreach (MyDataRow in Mydata.Expense[5].rows) MySum = MySum + convert.ToInt32(MyDataRow["Expense"]) end for Pardon my coding cause i'm very new to vb. Any help would be greatful or a working example that uses vb.net asp.net with visual studios 2005 that explains this would be wonderful. I manually coded my dataset but used the designer to make the datagrid not sure if thats a problem or not. Win32newb "Programming is like Sex, make a mistake and you end up providing support for a long time"

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      First of all check out the object browser, it is your friend. Now to sum data in a datatable do something like this. 'DT is the datatable dim intexpenses As Integer Dim intCount As Integer = DT.Rows.Count - 1 For intIndex As Integer = 0 To intCount Dim r As DataRow = DT.Rows(intIndex) intexpenses + = cint(r.item("Expense")) next how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

      M 2 Replies Last reply
      0
      • T ToddHileHoffer

        First of all check out the object browser, it is your friend. Now to sum data in a datatable do something like this. 'DT is the datatable dim intexpenses As Integer Dim intCount As Integer = DT.Rows.Count - 1 For intIndex As Integer = 0 To intCount Dim r As DataRow = DT.Rows(intIndex) intexpenses + = cint(r.item("Expense")) next how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

        M Offline
        M Offline
        MeterMan
        wrote on last edited by
        #3

        Thanks one quick question how do you know what the datatable name is on a datagrid that you made with designer? I can't find it anywhere :( Sorry to be a pest. Do i simply have to make a datatable too? Win32newb "Programming is like Sex, make a mistake and you end up providing support for a long time"

        T 1 Reply Last reply
        0
        • M MeterMan

          Thanks one quick question how do you know what the datatable name is on a datagrid that you made with designer? I can't find it anywhere :( Sorry to be a pest. Do i simply have to make a datatable too? Win32newb "Programming is like Sex, make a mistake and you end up providing support for a long time"

          T Offline
          T Offline
          ToddHileHoffer
          wrote on last edited by
          #4

          How are you binding the data? The datatable usually comes from a call to a database via the dataAdapter or datareader. how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

          I M 2 Replies Last reply
          0
          • M MeterMan

            For some reason I can't seem to get DataRow to come up in intellatype or whatever its called. What I have is a datagrid with a bound datasourse of Mydata. I want to count the values for the expense field and put them into a text box at the bottom of the page. My assumption was I could do something like the following. Dim MyDataRow as DataRow Dim MySum as integer foreach (MyDataRow in Mydata.Expense[5].rows) MySum = MySum + convert.ToInt32(MyDataRow["Expense"]) end for Pardon my coding cause i'm very new to vb. Any help would be greatful or a working example that uses vb.net asp.net with visual studios 2005 that explains this would be wonderful. I manually coded my dataset but used the designer to make the datagrid not sure if thats a problem or not. Win32newb "Programming is like Sex, make a mistake and you end up providing support for a long time"

            I Offline
            I Offline
            Ista
            wrote on last edited by
            #5

            The reason is because the "indexer" resolves to an object which doesnt have any methods. Well it does, but thier not always shown like that. Use your object broswer and do a search for the object you want to investigate. Your code is fine 1 line of code equals many bugs. So don't write any!!

            1 Reply Last reply
            0
            • T ToddHileHoffer

              How are you binding the data? The datatable usually comes from a call to a database via the dataAdapter or datareader. how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

              I Offline
              I Offline
              Ista
              wrote on last edited by
              #6

              ToddHileHoffer wrote:

              The datatable usually comes from a call to a database via the dataAdapter or datareader.

              Assuming they have the business rules are inside the form. If Its an OOP approach you wouldn't actually be manipualting DataTables inside the form. You can even bind to an arrayList or a custom class. The only requirement is it Implements IList in someway. DataTable is an IList 1 line of code equals many bugs. So don't write any!! -- modified at 12:06 Wednesday 22nd March, 2006

              1 Reply Last reply
              0
              • T ToddHileHoffer

                How are you binding the data? The datatable usually comes from a call to a database via the dataAdapter or datareader. how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

                M Offline
                M Offline
                MeterMan
                wrote on last edited by
                #7

                Well I think I am not doing it right Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' This code allows us to make a connect to the currently named db1 db ' for authentication tboxName.Text = Session("Username") dim uid as string = Session("Username") Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\Documents and Settings\tony.TONYWIN\My Documents\Visual Studio 2005\WebSites\PedalValveExpense\pvidb.mdb;User Id=admin; Password=;" Dim MySQL As String = "Select * from ExpenseReport" Dim MyConn As New System.Data.OleDb.OleDbConnection(strConn) 'makes a connection to the database based on connection string Dim objDR As System.Data.OleDb.OleDbDataReader 'reads the values into memory to reduce server overhead Dim Cmd As New System.Data.OleDb.OleDbCommand(MySQL, MyConn) 'executes the actual command to connect to the database Cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@uid", uid)) 'sets up a parameter of userID in the cookie with the userID its encypted by default MyConn.Open() ' opens the database connection objDR = Cmd.ExecuteReader() ' executes a commmand that actually reads thru the database While objDr.Read() tboxBeginDate.Text = objDR("tbxBeginDate").ToString() end while 'make a Dropdownlist box ' DropDownList1.DataSource = objDR 'dropdownlist1.DataTextField = "DateRow1" 'dropdownlist1.DataValueField = "DateRow1" 'dropdownlist1.DataBind() MyConn.Close() ' End Sub End Sub Protected Sub AddToDB_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddToDB.Click End Sub ' Protected Sub DropdownListBox() 'Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\Documents and Settings\tony.TONYWIN\My Documents\Visual Studio 2005\WebSites\PedalValveExpense\pvidb.mdb;User Id=admin; Password=;" 'Dim MySQL As String = "Select * from ExpenseReport" 'Dim MyConn As New System.Data.OleDb.OleDbConnection(strConn) 'makes a connection to the database based on connection string 'Dim objDR As System.Data.OleDb.OleDbDataReader 'reads the values into memory to reduce server overhead 'Dim Cmd As New System.Data.OleDb.OleDbCommand(MySQL, MyConn) 'executes the actual command to connect to the d

                T 1 Reply Last reply
                0
                • M MeterMan

                  Well I think I am not doing it right Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' This code allows us to make a connect to the currently named db1 db ' for authentication tboxName.Text = Session("Username") dim uid as string = Session("Username") Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\Documents and Settings\tony.TONYWIN\My Documents\Visual Studio 2005\WebSites\PedalValveExpense\pvidb.mdb;User Id=admin; Password=;" Dim MySQL As String = "Select * from ExpenseReport" Dim MyConn As New System.Data.OleDb.OleDbConnection(strConn) 'makes a connection to the database based on connection string Dim objDR As System.Data.OleDb.OleDbDataReader 'reads the values into memory to reduce server overhead Dim Cmd As New System.Data.OleDb.OleDbCommand(MySQL, MyConn) 'executes the actual command to connect to the database Cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@uid", uid)) 'sets up a parameter of userID in the cookie with the userID its encypted by default MyConn.Open() ' opens the database connection objDR = Cmd.ExecuteReader() ' executes a commmand that actually reads thru the database While objDr.Read() tboxBeginDate.Text = objDR("tbxBeginDate").ToString() end while 'make a Dropdownlist box ' DropDownList1.DataSource = objDR 'dropdownlist1.DataTextField = "DateRow1" 'dropdownlist1.DataValueField = "DateRow1" 'dropdownlist1.DataBind() MyConn.Close() ' End Sub End Sub Protected Sub AddToDB_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddToDB.Click End Sub ' Protected Sub DropdownListBox() 'Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\Documents and Settings\tony.TONYWIN\My Documents\Visual Studio 2005\WebSites\PedalValveExpense\pvidb.mdb;User Id=admin; Password=;" 'Dim MySQL As String = "Select * from ExpenseReport" 'Dim MyConn As New System.Data.OleDb.OleDbConnection(strConn) 'makes a connection to the database based on connection string 'Dim objDR As System.Data.OleDb.OleDbDataReader 'reads the values into memory to reduce server overhead 'Dim Cmd As New System.Data.OleDb.OleDbCommand(MySQL, MyConn) 'executes the actual command to connect to the d

                  T Offline
                  T Offline
                  ToddHileHoffer
                  wrote on last edited by
                  #8

                  Dim dt as new datatable Dim da1 As New OleDb.OleDbDataAdapter da1.SelectCommand = cmd myConn.open() da1.Fill(dt) myconn.dispose() dim intexpenses As Integer Dim intCount As Integer = DT.Rows.Count - 1 For intIndex As Integer = 0 To intCount Dim r As DataRow = DT.Rows(intIndex) intexpenses + = cint(r.item("Expense")) Next datagrid.datasource = dt datagrid.databind how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

                  1 Reply Last reply
                  0
                  • T ToddHileHoffer

                    First of all check out the object browser, it is your friend. Now to sum data in a datatable do something like this. 'DT is the datatable dim intexpenses As Integer Dim intCount As Integer = DT.Rows.Count - 1 For intIndex As Integer = 0 To intCount Dim r As DataRow = DT.Rows(intIndex) intexpenses + = cint(r.item("Expense")) next how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

                    M Offline
                    M Offline
                    MeterMan
                    wrote on last edited by
                    #9

                    Thanks a million it worked I modified it and commented it like crasy so I could understand it. Thanks again. Win32newb "Programming is like Sex, make a mistake and you end up providing support for a long time"

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups