Solved

VB.NET Dataset  - beginner ?

Posted on 2004-10-19
8
249 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

19 Experts available now in Live!

Get 1:1 Help Now