Solved

Why it is not updating in the Database?

Posted on 2006-10-22
14
183 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

20 Experts available now in Live!

Get 1:1 Help Now