Solved

Why it is not updating in the Database?

Posted on 2006-10-22
14
181 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Sending Text to device in .NET 9 32
Calculating a BCC (Xor) for a message 13 34
System32Int Error 8 44
VB.NET HttpWebRequest 12 34
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

12 Experts available now in Live!

Get 1:1 Help Now