Results 1 to 3 of 3

Thread: Finding the valid update command

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    74

    Question Finding the valid update command

    This is for visual basic 2008 express edition.Ive been trying to update records from the table of my memrec.dbml and dbase1DataSet.xsd in the visual basic environment.Im not using any sql database server but Im just using the built-in sql server within the visual basic 2008 express.I was able to add records and retreived it to display in the textboxes.My 1st block of codes I used to edit records has an error message which says:
    NotSupportedException was unhandled - Sql server does not handle comparison of NText, Text, Xml, or Image data types.

    My 2nd block of codes I tried to used doesn't have any error and it ables to change the records while at runtime but when you exit the program the changes was not save at all cause when you run it again the records that were changed during runtime goes back to its original records.
    Let me take you a look at the two blocks of codes
    ******************1st block of codes***********************
    Private Sub Button5_Click(------------------) Handles Button5.Click
    If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Then
    MsgBox("Please Fill It Up Completely",MsgBoxStyle.Exclamation)
    Exit Sub
    Else

    Dim accnt As String
    accnt = TextBox1.Text
    Dim db As New memrecDataContext()

    Dim editrecord = _
    From memrec In db.Table1s _
    Where memrec.Account.Contains(accnt) _
    Select memrec

    For Each memrec In editrecord
    If memrec.Account = accnt Then

    memrec.Account = TextBox1.Text
    memrec.Name = TextBox2.Text
    memrec.Address = TextBox3.Text
    memrec.Gender = TextBox4.Text
    db.SubmitChanges()

    Exit Sub
    End If
    Exit For
    Next

    MsgBox("No Records Match",MsgBoxStyle.Information)
    End If
    End Sub
    ********************************************************
    *****************2nd block of codes*************************
    Private Sub Button5_Click(------------------) Handles Button5.Click
    If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Then
    MsgBox("Please Fill It Up Completely",MsgBoxStyle.Exclamation)
    Exit Sub
    Else

    Dim accnt As String
    accnt = TextBox1.Text

    Dim editrecord = _
    From memrec In Form6.dbase1DataSet.Table1 _ 'instead of db.Table1s
    Where memrec.Account.Contains(accnt) _
    Select memrec

    For Each memrec In editrecord
    If memrec.Account = accnt Then

    memrec.Account = TextBox1.Text
    memrec.Name = TextBox2.Text
    memrec.Address = TextBox3.Text
    memrec.Gender = TextBox4.Text

    Exit Sub
    End If
    Exit For
    Next

    MsgBox("No Records Match",MsgBoxStyle.Information)
    End If
    End Sub
    *****************************************************
    For the 2nd block of codes,i tried to add update command to save the changes after you exit the program and the 1st code I added was Form6.dbase1DataSet.SubmitChanges() but visual basic 2008 express wont give you an option to select SubmitChanges().The 2nd code I tried to add was Form6.Table1TableAdapter.Update(Form6.dbase1DataSet.Table1) but it still leaves an error message says:InvalidOperationException was unhandled-Update requires a valid update command when passed datarow collection with modified rows.

    Questions:
    1.What do you see as possible cause for having an error in 1st block of codes?What's the remedy for that?

    2.For the 2nd block of codes,what is the valid update command to be added in the line in order to save the changes not just during runtime but until you exit the program and run it again?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Finding the valid update command

    It sounds like your table doesn't have a primary key. The system can't uniquely identify a record without a primary key so it won't update data for you.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    74

    Thumbs up Re: Finding the valid update command

    I was able to resolved it myself,its a matter of setting in its data type cause when i setup the table i changed it as text in a first place and not varchar() instead,but thank you anyway for your idea.....

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width