Solved

VB.NET Dataset  - beginner ?

Posted on 2004-10-19
8
250 Views
Last Modified: 2010-04-23
I have the following code that adds a row to an sql table. I have modifed the code to select a specific record and update it instead of adding a new record.


      Dim da As New SqlDataAdapter _
         ("Select * From Customers", con)
        Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
        Dim ds As New DataSet
        da.MissingSchemaAction = MissingSchemaAction.AddWithKey
        Try
            Dim fs As New FileStream _
             (fullFilePath, FileMode.OpenOrCreate, _
              FileAccess.Read)
            Dim MyData(fs.Length) As Byte
            fs.Read(MyData, 0, fs.Length)
            fs.Close()
            con.Open()
            da.Fill(ds, "Customers")
            Dim myRow As DataRow
            myRow = ds.Tables("Customers").NewRow()
            myRow("CheckInDate") = Now
            myRow("LastCheckin") = myName
            myRow("CustomerName") = CompanyName
            myRow("CustomerFile") = MyData
            ds.Tables("Customers").Rows.Add(myRow)
            da.Update(ds, "Customers")





0
Comment
Question by:JonMny
8 Comments
 
LVL 4

Expert Comment

by:eozz_2000
ID: 12352980
What is your question?
0
 
LVL 9

Author Comment

by:JonMny
ID: 12353026
Sorry, I was not clear. The code currently adds a new row I want it to update a row
0
 
LVL 7

Expert Comment

by:J_Mak
ID: 12353639
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:eozz_2000
ID: 12354559
I would search into the rows collection of the table until I have got the row that I want to update, something like this:

daSample.Fill(dsSample,"Customers")

for i = 0 to dsSample.Tables("Customers").Rows.Count - 1
  if dsSample.Tables("Customers").Rows(i).Item("Name") = "George" then
    dsSample.Tables("Customers").Rows(i).Item("Name") = "John"
    daSample.Update(dsSample.Tables("Customers"))
    exit For
  end if
next
0
 
LVL 2

Expert Comment

by:ahmadfuwad
ID: 12354865
'Try following code for adding and updating row in dataset

daSample.Fill(dsSample,"Customers")


            Dim r As DataRow
            dsSample.Tables("Customers").NewRow()
            dsSample.Tables("Customers").Rows.Add(r)

  if dsSample.Tables("Customers").Rows(dsSample.Tables("Customers").Rows.Count-1).Item("Name") = "George" then
    dsSample.Tables("Customers").Rows(dsSample.Tables("Customers").Rows.Count-1).Item("Name") = "John"

Dim oCommandBuilder As New SqlCommandBuilder(daSample)
            daSample.Update(dsSample, dsSample.Tables("Customers"))
0
 
LVL 4

Accepted Solution

by:
eozz_2000 earned 500 total points
ID: 12354915
Well, in the case above you are actually adding and then updating the last row that you have added, in my code you update a certain row (the row you want to update)
0
 
LVL 4

Expert Comment

by:eozz_2000
ID: 12707627
I think my answer has solved the problem :S
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now