Counting Values in a Datagrid Vb.net asp.net visual studios 2005
-
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"
-
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"
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
-
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
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"
-
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"
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
-
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"
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!!
-
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
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
-
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
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
-
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
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
-
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