Solved

Why it is not updating in the Database?

Posted on 2006-10-22
14
184 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now