Solved

Why it is not updating in the Database?

Posted on 2006-10-22
14
185 Views
Last Modified: 2010-05-18
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
Comment
Question by:JackOfPH
14 Comments
 
LVL 13

Assisted Solution

by:newyuppie
newyuppie earned 100 total points
ID: 17786469
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
 
LVL 15

Author Comment

by:JackOfPH
ID: 17786598
There is a datagridview binded in the binding source...
But i am not getting any data from it.. I was inserting data manually...
0
 
LVL 15

Author Comment

by:JackOfPH
ID: 17786614
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
LVL 15

Author Comment

by:JackOfPH
ID: 17786657
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
 
LVL 15

Author Comment

by:JackOfPH
ID: 17786789
Please help...
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17786917
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
 
LVL 15

Author Comment

by:JackOfPH
ID: 17786952
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
 
LVL 15

Author Comment

by:JackOfPH
ID: 17787171
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
 
LVL 13

Expert Comment

by:newyuppie
ID: 17787203
>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
 
LVL 15

Author Comment

by:JackOfPH
ID: 17787301
>>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
 
LVL 34

Accepted Solution

by:
Sancler earned 300 total points
ID: 17787413
Have a look at this

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

Does that ring any bells?

Roger
0
 

Assisted Solution

by:VRTech
VRTech earned 100 total points
ID: 17789299
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
 
LVL 15

Author Comment

by:JackOfPH
ID: 17792516
>>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
 
LVL 15

Author Comment

by:JackOfPH
ID: 17792521
Thanks for your comment guys...

{Jack}
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

861 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