?
Solved

Using update command for Typed DataSets dataadapter

Posted on 2006-04-11
1
Medium Priority
?
192 Views
Last Modified: 2011-09-20
I am trying to do an update to the database based on my typed dataset, here is the code i have and it doesnt seem to be inserting anything.  


    Dim qds As New dsQuestions
    Dim qda As New dsQuestionsTableAdapters.QuestionsTableAdapter
    Dim qdt As New dsQuestions.QuestionsDataTable
    Dim qdr As dsQuestions.QuestionsRow

    Protected Sub btnAddAnother_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        qda.Fill(qdt)
        qdr = CType(qdt.NewRow, dsQuestions.QuestionsRow)

        With qdr
            .BeginEdit()
            Select Case ddlQuestionType.SelectedValue.ToLower
                Case "test"
                    .TestID = CInt(Request.QueryString("id"))
                Case "workbook"
                    .WorkbookID = CInt(Request.QueryString("id"))
            End Select
            .QuestionText = txtQuestion.Text
            .QuestionType = 1
            .Answer1 = TextBox1.Text
            .Answer2 = TextBox2.Text
            .Answer3 = TextBox3.Text
            .Answer4 = TextBox4.Text
            .Answer5 = TextBox5.Text
            If .HasErrors Then
                Throw New Exception("there are errors")
            End If
            .EndEdit()

        End With
        qdt.ImportRow(qdr)
        qda.Update(qdt)

    End Sub
0
Comment
Question by:rodmjay
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 16436090
Comments:

1) You are filling dsQuestions.QuestionsDataTable and not the DataSet, so why have a DataSet.
2) To add rows, follow these steps:

   a) Create a new row
   b) Set the values
   c) Add the row to the DataTable.

     qdr = qdt.NewQuestionsRow()
 
     qdr.QuestionText = txtQuestion.Text
     qdr.QuestionType = 1
     qdr.Answer1 = TextBox1.Text
     qdr.Answer2 = TextBox2.Text
     qdr.Answer3 = TextBox3.Text
     qdr.Answer4 = TextBox4.Text
     qdr.Answer5 = TextBox5.Text
 
     qdt.AddQuestionsRow(qdr)

Bob
0

Featured Post

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!

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
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. …
Suggested Courses
Course of the Month16 days, 6 hours left to enroll

850 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