Thursday, March 22, 2012

Looping through a database using the dataview

I want to loop through my database using the already created dataview so that I can modify a field in each record. I already have the dataview created because I used it in my datagrid. My goal now is to use a button-click command to loop through each record in the dataset so that I can update the recordset.

Thanks in advance to one and all!

MarkI beleive that I have found the right method - "dataview.allowedit". However the database is not updated when I run the routine. Here is my structure:

Dim norec As Integer
Dim count As Integer
DataView1.AllowEdit = True
norec = DataView1.Count()
For count = 0 To norec - 1
DataView1(count).BeginEdit()
If DataView1(count)("selectforpay") = 1 Then
DataView1(count)("PayType") = "J"
DataView1(count)("PayDate") = Format(CDate(CalPaydate.SelectedDate), "Short Date")
TextBox1.Text = DataView1(count)("Paydate")
End If
DataView1(count).EndEdit()

Next
DataView1.AllowEdit = False

Why doesn't this routine update the database?

Any help is greatly appreciated!

Mark
In my opinion the easiest and best way to perform updates on a database is by using a DataSet representation of the data (generated by the Visual Studio .NET designer in order to have the INSERT, UPDATE, DELETE and SELECT commands in place) and then manipulate the data in the dataset (offline from the database). When you have finished adding, editing, deleting rows, call the Update method of the dataset to flush the changes to the database.

Does this help you?
could you provide a little slice of code to illustrate to me what you are saying. I understand what you are saying, but I don't know how to tell ASP.NET to do it.

Thaks in Advance
It's rather large to post over here, so I'll post a link to an article that covers part of this technique:

Main link:http://www.developerfusion.com/show/3801/
Link with info on updating the database:
http://www.developerfusion.com/show/3801/4/

Take your time to read the entire article and try it out on your own. You'll see it not that complex, but you should have done it once to kick off with it in your own application. The article assumes you're using Visual Studio .NET to generate the DataAdapter with all the needed command objects.
Thank you!

After I started to read the article that you sent me (Thanks a mil) it didn't take long to fiqure out what I was doing wrong. I needed to add the

SqlDataAdapter1.Update(Dsselforpay1)

command to my code. You save the day for me - Thank you!

Mark

0 comments:

Post a Comment