473,388 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Update DataRow

When a DataGrid is in the editable mode, users can change the quantity
of the items that are currently in his shopping cart by entering a new
quantity in a TextBox. After changing the quantity, a column named
*Quantity* in a database table also gets updated with the changes made
by the user. The Form has a Label as well which shows the total cost
of all the items that are currently present in his cart. This the
OnUpdateCommand event handler of the DataGrid:

========================================
Sub UpdateCart(obj As Object, ea As DataGridCommandEventArgs)
Dim i As Integer
Dim iQty As Integer
Dim iTotal As Integer
Dim strSQL As String
Dim dTable As DataTable
Dim dRowTotal() As DataRow
Dim oleDbCmd As OleDbCommand
Dim oleDbConn As OleDbConnection

oleDbConn = New OleDbConnection(".........")
iQty = CType(ea.Item.Cells(4).Controls(0), TextBox).Text

strSQL = "UPDATE tblCart SET Quantity=" & iQty & " WHERE........"

oleDbCmd = New OleDbCommand(strSQL, oleDbConn)

oleDbConn.Open()
oleDbCmd.ExecuteNonQuery()

strSQL = "SELECT * FROM tblCart WHERE ......."
oleDbDapter = New OleDbDataAdapter(strSQL, oleDbConn)

dSet = New DataSet()
oleDbDapter.Fill(dSet, "Cart")

dTable = New DataTable
dTable = dSet.Tables("Cart")
dSet.Tables("Cart").AcceptChanges()
dRowTotal = dTable.Select(Nothing, "Total",
DataViewRowState.CurrentRows)

iTotal = 0

For i = 0 To dRowTotal.Length - 1
dTable.Rows(i).AcceptChanges()
Response.Write("Total: " & dRowTotal(i)("Total") & "<br>")
iTotal = iTotal + dRowTotal(i)("Total")
Next

lblTotal.Text = "TOTAL : " & iTotal & ".00"

dgCart.DataSource = dSet.Tables("Cart").DefaultView
'oleDbDapter.Update(dSet, "Cart")
oleDbConn.Close()

dgCart.EditItemIndex = -1
dgCart.DataBind()
End Sub
========================================

The above code successfully updates the *Quantity* column in the DB
table.

Assume that the total cost of all the items amounts to 1000. The user
then decides to update the quantity of an item (whose unit price is
200) from 1 to 3 which means that after updating the quantity, the
total cost should now be 1400 i.e. the Label should now display 1400
but the Label still retains the old value & wrongly displays the total
cost as 1000.

Where am I erring here?

Feb 23 '07 #1
2 1976
On Feb 23, 8:50 am, r...@rediffmail.com wrote:
When a DataGrid is in the editable mode, users can change the quantity
of the items that are currently in his shopping cart by entering a new
quantity in a TextBox. After changing the quantity, a column named
*Quantity* in a database table also gets updated with the changes made
by the user. The Form has a Label as well which shows the total cost
of all the items that are currently present in his cart. This the
OnUpdateCommand event handler of the DataGrid:

========================================
Sub UpdateCart(obj As Object, ea As DataGridCommandEventArgs)
Dim i As Integer
Dim iQty As Integer
Dim iTotal As Integer
Dim strSQL As String
Dim dTable As DataTable
Dim dRowTotal() As DataRow
Dim oleDbCmd As OleDbCommand
Dim oleDbConn As OleDbConnection

oleDbConn = New OleDbConnection(".........")
iQty = CType(ea.Item.Cells(4).Controls(0), TextBox).Text

strSQL = "UPDATE tblCart SET Quantity=" & iQty & " WHERE........"

oleDbCmd = New OleDbCommand(strSQL, oleDbConn)

oleDbConn.Open()
oleDbCmd.ExecuteNonQuery()

strSQL = "SELECT * FROM tblCart WHERE ......."
oleDbDapter = New OleDbDataAdapter(strSQL, oleDbConn)

dSet = New DataSet()
oleDbDapter.Fill(dSet, "Cart")

dTable = New DataTable
dTable = dSet.Tables("Cart")
dSet.Tables("Cart").AcceptChanges()
dRowTotal = dTable.Select(Nothing, "Total",
DataViewRowState.CurrentRows)

iTotal = 0

For i = 0 To dRowTotal.Length - 1
dTable.Rows(i).AcceptChanges()
Response.Write("Total: " & dRowTotal(i)("Total") & "<br>")
iTotal = iTotal + dRowTotal(i)("Total")
Next

lblTotal.Text = "TOTAL : " & iTotal & ".00"

dgCart.DataSource = dSet.Tables("Cart").DefaultView
'oleDbDapter.Update(dSet, "Cart")
oleDbConn.Close()

dgCart.EditItemIndex = -1
dgCart.DataBind()
End Sub
========================================

The above code successfully updates the *Quantity* column in the DB
table.

Assume that the total cost of all the items amounts to 1000. The user
then decides to update the quantity of an item (whose unit price is
200) from 1 to 3 which means that after updating the quantity, the
total cost should now be 1400 i.e. the Label should now display 1400
but the Label still retains the old value & wrongly displays the total
cost as 1000.

Where am I erring here?
No one to help me out?? I thought this must be a not-so-difficult to
answer question!

Feb 24 '07 #2
On Feb 24, 3:13 pm, r...@rediffmail.com wrote:
On Feb 23, 8:50 am, r...@rediffmail.com wrote:


When a DataGrid is in the editable mode, users can change the quantity
of the items that are currently in his shopping cart by entering a new
quantity in a TextBox. After changing the quantity, a column named
*Quantity* in a database table also gets updated with the changes made
by the user. The Form has a Label as well which shows the total cost
of all the items that are currently present in his cart. This the
OnUpdateCommand event handler of the DataGrid:
========================================
Sub UpdateCart(obj As Object, ea As DataGridCommandEventArgs)
Dim i As Integer
Dim iQty As Integer
Dim iTotal As Integer
Dim strSQL As String
Dim dTable As DataTable
Dim dRowTotal() As DataRow
Dim oleDbCmd As OleDbCommand
Dim oleDbConn As OleDbConnection
oleDbConn = New OleDbConnection(".........")
iQty = CType(ea.Item.Cells(4).Controls(0), TextBox).Text
strSQL = "UPDATE tblCart SET Quantity=" & iQty & " WHERE........"
oleDbCmd = New OleDbCommand(strSQL, oleDbConn)
oleDbConn.Open()
oleDbCmd.ExecuteNonQuery()
strSQL = "SELECT * FROM tblCart WHERE ......."
oleDbDapter = New OleDbDataAdapter(strSQL, oleDbConn)
dSet = New DataSet()
oleDbDapter.Fill(dSet, "Cart")
dTable = New DataTable
dTable = dSet.Tables("Cart")
dSet.Tables("Cart").AcceptChanges()
dRowTotal = dTable.Select(Nothing, "Total",
DataViewRowState.CurrentRows)
iTotal = 0
For i = 0 To dRowTotal.Length - 1
dTable.Rows(i).AcceptChanges()
Response.Write("Total: " & dRowTotal(i)("Total") & "<br>")
iTotal = iTotal + dRowTotal(i)("Total")
Next
lblTotal.Text = "TOTAL : " & iTotal & ".00"
dgCart.DataSource = dSet.Tables("Cart").DefaultView
'oleDbDapter.Update(dSet, "Cart")
oleDbConn.Close()
dgCart.EditItemIndex = -1
dgCart.DataBind()
End Sub
========================================
The above code successfully updates the *Quantity* column in the DB
table.
Assume that the total cost of all the items amounts to 1000. The user
then decides to update the quantity of an item (whose unit price is
200) from 1 to 3 which means that after updating the quantity, the
total cost should now be 1400 i.e. the Label should now display 1400
but the Label still retains the old value & wrongly displays the total
cost as 1000.
Where am I erring here?

No one to help me out?? I thought this must be a not-so-difficult to
answer question!- Hide quoted text -

- Show quoted text -
No offence intended but I swear that this newsgroup is the dumbest
newsgroup I have ever come across. I don't get answers for fundamental
questions even after 4-5 days! It's really strange. And I thought that
the ones answering questions in this post are ASP.NET experts, gurus &
MVPs.

I know it isn't mandatory for anyone to answer the posts that people
like me post in this newsgroup (rather any of the newsgroups) & that
people answering others' posts are doing it voluntarily for which they
aren't paid & I genuinely feel from the bottom of my heart that what
they are doing is highly praiseworthy more so because in todays world,
no one does anything for others without any personal gains but on some
occasions, I find it hard to digest that I don't get answers for even
simple & fundamental questions. It's too frustrating.

I have been using the Google archived newsgroups like ASP, SQL Server,
DataGrid, VB, IIS, Access, Win2K, WinXP etc.. since last 7-8 years &
have a lot of faith in it but never have I encountered anything like
this where my presumably simple posts have gone unanswered for days on
end.

Once again let me iterate that I don't intend to offend anyone.....now
just sit back & watch how many responses I get for this tirade.

Feb 28 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mojtaba Faridzad | last post by:
Hi, Please check these lines: DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet, "mytable"); DataRow row; row = dataSet.Tables.Rows; row.BeginEdit(); row = "555";
7
by: Steve B. | last post by:
Does anyone know why the DA Update() would throw an exception? I moved the database but I updated the Conn and the DA, currently (trying)removing/replacing DS. Is there a another direction I...
0
by: Doug | last post by:
I've got a strongly-typed dataset with 2 related tables in it ("Staff" and "Roles"). I want to make a change to the parent Staff row and also to its child Role row. I'm having difficulty figuring...
4
by: CaptRR | last post by:
I think this is the right group to post to, so here goes. My problem is this, I cannot update the datarow to save my life. Been on this for 2 days now, and still am no closer to figuring it out...
15
by: graham | last post by:
Hi all, <bitching and moaning section> I am asking for any help I can get here... I am at the end of my tether... I don;t consider myself a genius in any way whatsoever, but I do believe I have...
6
by: Wanda | last post by:
Hello, I tried to update a row in a table by using the datarow and data adapter. Unfortunately, it doesn't update. I try finding that datarow and set it to "dr", I can see dr could be just an...
4
by: George | last post by:
Got a question about the side effect of DataAdapter.Update() and DataTable.GetChanges(). Say I set up a DataTable and a DataAdapter in a class. Delete (Not remove) a row in the data table and...
5
by: Stephen Plotnick | last post by:
I'm very new to VB.NET 2003 Here is what I have accomplished: MainSelectForm - Selects an item In a public class I pass a DataViewRow to ItemInformation1 Form ItemInformation2 Form
3
by: Fred Chateau | last post by:
Any obvious reason here why data is not being loaded into the database? SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommand); SqlCommandBuilder commandBuilder = new...
0
by: riyap | last post by:
Hi i have a question regarding a update in msaccess DB using string builder,DATA SET AND DATA RELATIONS can we do that in access DB i have a table in access i need to pass more than 1 record and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.