Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.NET Dataset  - beginner ?

Posted on 2004-10-19
8
Medium Priority
?
259 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

916 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