Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

Why it is not updating in the Database?

I used this statements to add to the database...
It update the dataset but it does not add the records to the database... why?
Please explain...
here is the code I used..

Me.TblTransactionTableAdapter.Insert("Meeting Room 1", Format(Me.MonthCalendar1.SelectionRange.Start, "MMMM dd, yyyy"), ctrTime & ":00 AM", ctrTime + 1 & ":00 PM", False, "", "")

Me.TblTransactionBindingSource.EndEdit()
Me.TblTransactionTableAdapter.Update(Me.DsRoomReservation.tblTransaction)

I am using vb 2005 express edition...
0
JackOfPH
Asked:
JackOfPH
3 Solutions
 
newyuppieCommented:
sounds like when you use the Insert method of the TableAdapter you are in fact updating the database with this info. Then, as the datatable tblTransaction has nothing in it, when you call the Update method of the TableAdapter you are overwriting the first insert.

from your code, you have a BindingSource in place, so where are you using that? did you bind any controls on the form to this binding source at all? if you did (at design time) you should skip the Insert line as the changes will get back to the database through the Update method and the Binding Source.

if you havent binded any control and wish to add the record manually, either

1) use only the insert method and delete the last two lines (bindingsource.endedit() and tableadapter.update() )
2) or replace the insert method with something along these lines:

Dim newTransactionRow As DsRoomReservation.tblTransactionRow
newTransactionRow = DsRoomReservation.tblTransaction.NewtblTransactionRow ()

newTransactionRow.Place = "Meeting Room 1"      'replace "place" with the column name that should go here
newTransactionRow.Time = Format(Me.MonthCalendar1.SelectionRange.Start, "MMMM dd, yyyy")
etc...

DsRoomReservation.tblTransaction.Rows.Add(newTransactionRow )

Me.TblTransactionTableAdapter.Update(Me.DsRoomReservation.tblTransaction)


untested, but hope this helps

NY

0
 
JackOfPHAuthor Commented:
There is a datagridview binded in the binding source...
But i am not getting any data from it.. I was inserting data manually...
0
 
JackOfPHAuthor Commented:
I tried this only...

 Me.TblTransactionTableAdapter.Insert("Meeting Room 1", Format(Me.MonthCalendar1.SelectionRange.Start, "MMMM dd, yyyy"), ctrTime & ":00 AM", ctrTime + 1 & ":00 PM", False, "", "")

It shows the new record in the datagridview but when I open the database (access) it does not contain the new record...

0
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!

 
JackOfPHAuthor Commented:
I try this

 Dim newTransactionRow As dsRoomReservation.tblTransactionRow
            newTransactionRow = DsRoomReservation.tblTransaction.NewtblTransactionRow()
            With newTransactionRow
                .RoomNumber = "Meeting Room 1"
                .StartTime = ctrTime
                .EndTime = ctrTime + 1 & ":00 PM"
                .Occupied = True
                .Purpose = ""
                .ReservedBy = ""
                ._Date = Format(Me.MonthCalendar1.SelectionRange.Start)
            End With
            DsRoomReservation.tblTransaction.Rows.Add(newTransactionRow)
            Me.TblTransactionTableAdapter.Update(Me.DsRoomReservation.tblTransaction)

But it is not working...
0
 
JackOfPHAuthor Commented:
Please help...
0
 
newyuppieCommented:
i dont see anything wrong with any of your 2 examples, maybe somebody will correct me but i think they should be working, provided that your connection string to the database is correct. are you checking the right database to see if record was updated? i mean, did you add the database to your project? if so, are you checking the database in the bin/release (or debug) folder to check for the updates?
0
 
JackOfPHAuthor Commented:
I tried to publish the program and run the program on my computer. When I run the program and add new records to the database the records was added to the grid.  I close the program and open the the program again, the added record is still there... and when I open the database the records is now there...

But during program creation, when I tried to run the progam and add some records. It show in the datagridview what I added. But when I close (hit the stop) and run the program again the record I added earlier is gone...

Is this usual? Is it true that during the program creation when you add data to the database it will not actually add the record to the database? Does Adding of records will only take effect when the program is publish or complied?

Thanks..

{Jack}

0
 
JackOfPHAuthor Commented:
Clarification...
>> I tried to publish the program and run the program on my computer.

What I mean here is I publish and install the program on my computer... And run the program....
0
 
newyuppieCommented:
>Is this usual? Is it true that during the program creation when you add data to the database it will not actually add the >record to the database? Does Adding of records will only take effect when the program is publish or complied?

no thats not true. thing is, your empty database, the one you start with before adding any records, gets copied to the output directory every time you compile and run your application. so, any changes you have made during the testing will reset when you compile again. thats why you can see the changes when you are using the release version without recompiling.
0
 
JackOfPHAuthor Commented:
>>But during program creation, when I tried to run the progam and add some records. It show in the datagridview what I added. But when I close (hit the stop) and run the program again the record I added earlier is gone...

Why?
0
 
SanclerCommented:
Have a look at this

http://msdn2.microsoft.com/en-us/library/ms233817.aspx

Does that ring any bells?

Roger
0
 
VRTechCommented:
Your insert statement should actually be hitting the database and not the table adapter.  A SQLCommand statement such as the one below is what I am using, as an example.

Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

        'Declare the local variables and objects
        Dim intPosition As Integer
        Dim objCommand As SqlCommand = New SqlCommand

        'Save the current record position
        intPosition = objCurrencyManager.Position

        'Set the SqlCommand object properties
        objCommand.Connection = objconnection
        objCommand.CommandText = "Update tblAMQAI set FacilityID = @FacilityID, " & _
        "AreaMgrID = @AreaMgrID, DOR = @DOR, " & _
        "DateofReview = @DateofReview, AuditDesc = @AuditDesc, " & _
        "Record1 = @Record1, Record2 = @Record2, Record3 = @Record3, Record4 = @Record4, " & _
        "Record5 = @Record5, Record6 = @Record6, Record7 = @Record7, " & _
        "Record8 = @Record8, Record9 = @Record9, " & _
        "A0101 = @A0101, A0101chk = @A0101chk, A0101Count = @A0101Count, " & _
        "A0102 = @A0102, A0102chk = @A0102chk, A0102Count = @A0102Count, " & _
        "A0103 = @A0103, A0103chk = @A0103chk, A0103Count = @A0103Count, " & _
0
 
JackOfPHAuthor Commented:
>>The Copy to Output Directory is set to Copy if newer or Copy always. These settings will overwrite the database in your output folder (the database being modified when testing your application) every time you build your project.


So this is the explanation to my problem...

Thanks Sancler...

(I am just a begginer trying to learn vb.net on my own...)

{Jack}
0
 
JackOfPHAuthor Commented:
Thanks for your comment guys...

{Jack}
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now