Updating a database in VB.Net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mwcapps
    New Member
    • Mar 2009
    • 16

    Updating a database in VB.Net

    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.

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim cmdSave As New SqlClient.SqlCommand
            'Dim iRC As Integer
            Dim dsD As DataSet
            Dim adD As SqlClient.SqlDataAdapter
            Dim rowD As DataRow
            Dim i As Integer = 1
            Dim sD As String = "select * from table"
            Dim sU As String = ""
            Dim dsMax As DataSet
            Dim adMax As SqlClient.SqlDataAdapter
            Dim sMax As String = "select max(recid) + 1 as maxnum from table"
    
            dsD = New DataSet
            adD = New SqlClient.SqlDataAdapter(sD, gdbRecordSet)
            adD.Fill(dsD, "stuff")
    
            dsMax = New DataSet
            adMax = New SqlClient.SqlDataAdapter(sMax, gdbRecordSet)
            adMax.Fill(dsMax, "max")
    
            Dim maxnum As Double = dsMax.Tables("max").Rows(0)(0)
    
            For Each rowD In dsD.Tables("stuff").Rows
                'rowD.AcceptChanges()
                'rowD("recid") = i
                'rowD.SetModified()
                rowD.BeginEdit()
                rowD("recid") = i
                rowD.EndEdit()
    
                If dsD.HasChanges Then
                    dsD.AcceptChanges()
                    'adD.Update(dsD, "stuff")
                    'adD.Update(dsD.GetChanges())
                End If
                'sU = "update table set recid = '" & i & "' where  recid > '" & i & "'
               i = i + 1
                'cmdSave.Connection = gdbRecordSet
                'cmdSave.CommandText = sU
                'cmdSave.CommandType = CommandType.Text
                'iRC = cmdSave.ExecuteNonQuery
            Next
        End Sub
    Last edited by tlhintoq; Aug 18 '09, 06:02 PM. Reason: [CODE] ...your code goes here... [/CODE] tags added
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Please use [CODE] tags

    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.

    Comment

    Working...