Solved

VB.NET Dataset  - beginner ?

Posted on 2004-10-19
8
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: 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 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modal Popup Extender control 1 51
Looping through datagridview and dataset ? 6 33
How to repeat the data 4 30
vb.net sendkey 4 18
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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