473,396 Members | 1,810 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,396 software developers and data experts.

Updating a database in VB.Net

16
I have a sql database that contains several thousand records that need to be numbered sequentially from 1 through the end. I have tried several different ways and nothing seems to hit the database. I've included my attempts and would greatly appreciate any help.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim cmdSave As New SqlClient.SqlCommand
  3.         'Dim iRC As Integer
  4.         Dim dsD As DataSet
  5.         Dim adD As SqlClient.SqlDataAdapter
  6.         Dim rowD As DataRow
  7.         Dim i As Integer = 1
  8.         Dim sD As String = "select * from table"
  9.         Dim sU As String = ""
  10.         Dim dsMax As DataSet
  11.         Dim adMax As SqlClient.SqlDataAdapter
  12.         Dim sMax As String = "select max(recid) + 1 as maxnum from table"
  13.  
  14.         dsD = New DataSet
  15.         adD = New SqlClient.SqlDataAdapter(sD, gdbRecordSet)
  16.         adD.Fill(dsD, "stuff")
  17.  
  18.         dsMax = New DataSet
  19.         adMax = New SqlClient.SqlDataAdapter(sMax, gdbRecordSet)
  20.         adMax.Fill(dsMax, "max")
  21.  
  22.         Dim maxnum As Double = dsMax.Tables("max").Rows(0)(0)
  23.  
  24.         For Each rowD In dsD.Tables("stuff").Rows
  25.             'rowD.AcceptChanges()
  26.             'rowD("recid") = i
  27.             'rowD.SetModified()
  28.             rowD.BeginEdit()
  29.             rowD("recid") = i
  30.             rowD.EndEdit()
  31.  
  32.             If dsD.HasChanges Then
  33.                 dsD.AcceptChanges()
  34.                 'adD.Update(dsD, "stuff")
  35.                 'adD.Update(dsD.GetChanges())
  36.             End If
  37.             'sU = "update table set recid = '" & i & "' where  recid > '" & i & "'
  38.            i = i + 1
  39.             'cmdSave.Connection = gdbRecordSet
  40.             'cmdSave.CommandText = sU
  41.             'cmdSave.CommandType = CommandType.Text
  42.             'iRC = cmdSave.ExecuteNonQuery
  43.         Next
  44.     End Sub
Aug 18 '09 #1
1 1634
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.ly.
Aug 18 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
1
by: gaosul | last post by:
I am non-programming scientist and I am using a Program called Easyarticles from Synaptosoft Inc., which is based the database program Access. Unfortunately, the owner of this company has...
3
by: Bucko | last post by:
How important do you guys feel locking a database is while updating/adding information? Do you do it with every app you make? Only very high volume (traffic) apps? I'm trying to decide if my app...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
1
by: Luis Esteban Valencia | last post by:
Hello Everyone, Iam an intermediate ASP.Net programmer and iam facing a challenging task. I have a table in MS-SQL server database called 'Members'. The table has following fields... ...
3
by: | last post by:
Hello, I have created an ASP.NET 2.0 application that utilized a Gridview Control to display and update/delete data. The problem I am having is that the gridview control is displaying the data...
10
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1)...
2
by: Alexey.Murin | last post by:
The application we are developing uses MS Access 2003 database (with help of ADO). We have noticed that during massive records updating the size of the mdb file increases dramatically (from 3-4 to...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
1
by: jonbartlam | last post by:
Hi There I'm not sure what exactly is going wrong here. I'm writing an application that retreives a table from a database (tbl_internalfaults) and updates it. (Actually, just the status column will...
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:
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.