Solved

VB.NET Dataset  - beginner ?

Posted on 2004-10-19
8
254 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help with a query 14 53
Import a excel sheet in a grid 2 45
Best book for Internet security 4 53
Whice version VisualStudio for new Dev Laptop? 10 41
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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