Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Update DataTable..Da li moze?

[es] :: .NET :: Update DataTable..Da li moze?

[ Pregleda: 4111 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

patak_daca

Član broj: 72199
Poruke: 418
*.186.EUnet.yu.



+1 Profil

icon Update DataTable..Da li moze?11.12.2005. u 11:13 - pre 223 meseci
Da li se moze Update DataTable u VB.Net-u, i ako moze kako se to radi??
Prvo moram da Update DataTable pa zatim Bazu podataka.

Hvala unapred!
 
Odgovor na temu

Oliver Klaćik
Vice President, Thunder Road Software
Inc.
Stara Pazova

Član broj: 34059
Poruke: 242
80.93.231.*

Sajt: www.thunderroadsoftware.c..


Profil

icon Re: Update DataTable..Da li moze?12.12.2005. u 11:32 - pre 223 meseci
Kako misliš Update DataTable? Da promeniš neke podatke u njoj, naravno, možeš. Ali klasa DataTable u opšte nema metod Update.

Citat:
Izvor: MSDN 2003 - Editing Data in a Table

When you make changes to column values in a DataRow, the changes are immediately placed in the Current state of the row. The RowState is then set to Modified and the changes are accepted or rejected using the AcceptChanges or RejectChanges methods of the DataRow. The DataRow also provides three methods that you can use to suspend the state of the row while you are editing it. These methods are BeginEdit, EndEdit, and CancelEdit.

When you modify column values in a DataRow directly, the DataRow manages the column values using the Current, Default, and Original row versions. In addition to these row versions, the BeginEdit, EndEdit, and CancelEdit methods use a fourth row version: Proposed. For more information about row versions, see Row States and Row Versions.

The Proposed row version exists during an edit operation that is begun by calling BeginEdit and that is ended by using either EndEdit or CancelEdit or by calling AcceptChanges or RejectChanges.

During the edit operation you can apply validation logic to individual columns by evaluating the ProposedValue in the ColumnChanged event of the DataTable. The ColumnChanged event holds DataColumnChangeEventArgs that keep a reference to the column that is changing and the ProposedValue. After you evaluate the proposed value, you can either modify it or cancel the edit. When the edit is ended, the row moves out of the Proposed state.

You can confirm edits by calling EndEdit or you can cancel them by calling CancelEdit. Note that while EndEdit does confirm your edits, the DataSet does not actually accept the changes until AcceptChanges is called. Note also that if you call AcceptChanges before you have ended the edit with EndEdit or CancelEdit, the edit is ended and the Proposed row values are accepted for both the Current and Original row versions. In the same manner, calling RejectChanges ends the edit and discards the Current and Proposed row versions. Calling EndEdit or CancelEdit after calling AcceptChanges or RejectChanges has no effect because the edit has already ended.

The following example demonstrates how to use BeginEdit with EndEdit and CancelEdit. The example also checks the ProposedValue in the ColumnChanged event and decides whether to cancel the edit.


Code:

Dim workTable As DataTable = New DataTable
workTable.Columns.Add("LastName", Type.GetType("System.String"))

AddHandler workTable.ColumnChanged, New DataColumnChangeEventHandler(AddressOf OnColumnChanged)

Dim workRow As DataRow = workTable.NewRow()
workRow(0) = "Smith"
workTable.Rows.Add(workRow)

workRow.BeginEdit()
' Causes the ColumnChanged event to write a message and cancel the edit.
workRow(0) = ""     
workRow.EndEdit()

' Displays "Smith, New".
Console.WriteLine("{0}, {1}", workRow(0), workRow.RowState)  


Private Shared Sub OnColumnChanged(sender As Object, args As DataColumnChangeEventArgs)
  If args.Column.ColumnName = "LastName" Then
    If args.ProposedValue.ToString() = "" Then
      Console.WriteLine("Last Name cannot be blank.  Edit canceled.")
      args.Row.CancelEdit()
    End If
  End If
End Sub


Bez ljutnje, ali zašto prvo ne potražiš rešenje u MSDN-u ili na Internetu, jer bi ovde trebali da se bavimo rešavanjem malo ozbiljnijih problema, pa da svi mogu ponešto da nauče...
Oliver 'FAQ' Klaćik
 
Odgovor na temu

majstor_01

Član broj: 60008
Poruke: 63
*.my-its.net.



Profil

icon Re: Update DataTable..Da li moze?12.12.2005. u 15:03 - pre 223 meseci
Zdravo!

Koristis je isto kao i za DataSet

Znaci Adpter.Update(Table)
Npr
sqlDataAdapter1.Update(dataTable);

Pozdrav
 
Odgovor na temu

patak_daca

Član broj: 72199
Poruke: 418
*.191.eunet.yu.



+1 Profil

icon Re: Update DataTable..Da li moze?13.12.2005. u 18:39 - pre 223 meseci
Hvala puno!!
 
Odgovor na temu

[es] :: .NET :: Update DataTable..Da li moze?

[ Pregleda: 4111 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.