Results 1 to 22 of 22

Thread: ADO.NET Code - Simple (?)

Threaded View

  1. #9
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Okay, Karl, I've sucumbed to the emotional blackmail Here's the #'$%*@!!! code (needed to put the update after each record / in the loop :
    Code:
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim ConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=C:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB;" & _
            "Mode=ReadWrite;Persist Security Info=False;"
            Dim myConn As New ADO.ADOConnection(ConnStr)
            Dim myCommand As New ado.ADOCommand("SELECT * FROM Customers", myConn)
            Dim myDataSetCommand As New ado.ADODataSetCommand(myCommand)
            Dim myDataSet As New DataSet("Test1")
            
            Try
                myConn.Open()
                myDataSetCommand.FillDataSet(myDataSet, "Customers")
                Dim myRow As System.Data.DataRow
                
                For Each myRow In myDataSet.Tables("Customers").Rows
                    Console.WriteLine("Company Name: " & CStr(myRow("CompanyName")))
                    myRow("CompanyName") = CStr(myRow("CompanyName")) & " :c)"
                    myDataSetCommand.Update((myDataSet), ("Customers"))
                Next myrow
                
                Msgbox("Done !")
                
            Catch myException As Exception
                MsgBox(myException.ToString)
            Finally
                If myConn.State = DBObjectState.Open Then
                    myConn.Close()
                End If
                
                If Not myDataSet Is Nothing Then
                    myDataSet = Nothing
                End If
            End Try
        End Sub
    As above, my SQL server crashed so you'll need to modify the connection string - and you missed an End Try at the end, though I guess this is just part of the code you posted.

    Good luck & I look forward to reading the tutorial if it's anything like your others.
    Just 1 point more - why did you name this thread as "ADO.NET Code - SIMPLE ?!?!?!?!
    Last edited by alex_read; Apr 28th, 2001 at 08:43 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width