|
-
Dec 12th, 2001, 09:19 AM
#1
Thread Starter
New Member
from Db to DataGrid and back
Hi everyone,
i'm trying to construct a webapplication in 3-tier.....
I have to retrieve data from a SQL server DB passing this trough the 3 tiers(as a dataset) and display the table in a datagrid...
Next i have to add a Edit(Update, Cancel) column so that we can do in place editing in the Datagrid.
everything works fine but updating the dataset back to the DB
doesn't work....
I have read the article from KarlMoore because he had the same
problem, but the Accept changes thing does not work for me
Can somebody please help me because i'm out of resources?
Here is the code in 3 tier of course:
Aspx---->presentation layer
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FS = CArtiestenBO.HaalArtiesten()
If Not IsPostBack Then
BindGrid()
End If
End Sub
Sub MyDataGrid_Edit(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
MyDataGrid.EditItemIndex = e.Item.ItemIndex
BindGrid()
End Sub
Sub MyDataGrid_Cancel(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
MyDataGrid.EditItemIndex = -1
BindGrid()
End Sub
Sub MyDataGrid_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
' For bound columns the edited value is stored in a textbox,
' and the textbox is the 0th element in the column's cell
Dim Naam As TextBox = e.Item.Cells(2).Controls(0)
Dim Platenmaatschappij As TextBox = e.Item.Cell(3).Control(0)
Dim GeboorteDatum As TextBox = e.Item.Cells(4).Controls(0)
Dim ID As String = e.Item.Cells(1).Text
Dim ArtiestNaam As String = Naam.Text
Dim Platenm As String = Platenmaatschappij.Text
Dim Geboorte As String = GeboorteDatum.Text
Dim myRow As System.Data.DataRow
Dim i As Integer
i = 0
Do Until FS.Tables("Artiesten").Rows(i).Item(0) = CStr(ID)
i = i + 1
Loop
For Each myRow In FS.Tables("Artiesten").Rows
If myRow("ID") = FS.Tables("Artiesten").Rows(i).Item(0) Then
myRow("Artiestnaam") = CStr(ArtiestNaam)
myRow("PLatenmaatschappij") = CStr(Platenm)
myRow("Geboortedatum") = CStr(Geboorte)
myRow.AcceptChanges()
End If
Next
CArtiestenBO.UpdateArtiesten(FS)
MyDataGrid.EditItemIndex = -1
BindGrid()
End Sub
Sub BindGrid()
MyDataGrid.DataSource = FS.Tables("Artiesten")
MyDataGrid.DataBind()
End Sub
middle tier component---->Business Object
Public Function HaalArtiesten() As DataSet
Dim BS As DataSet
BS = CArtiestenDT.HaalArtiesten()
Return BS
End Function
Public Sub UpdateArtiesten(ByVal Update_BS As DataSet)
CArtiestenDT.UpdateArtiesten(Update_BS)
End Sub
Data tier component ---->Data
Dim ConnStr As String = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=CDCollectie;Data Source=(local)"
Dim MyConnection As OleDbConnection = New OleDbConnection(ConnStr)
Dim MyCommand As OleDbDataAdapter
Public Function HaalArtiesten() As DataSet
'######################R1
Dim DS As DataSet
'MyCommand = New SqlDataAdapter("SELECT AR_ID as ID, Ar_Naam as Artiestnaam, Ar_Platenmaatschappij as Platenmaatschappij, Ar_GeboorteDatum as Geboortedatum FROM tblArtiest", MyConnection)
MyCommand = New OleDbDataAdapter("SELECT AR_ID as ID, Ar_Naam as Artiestnaam, Ar_Platenmaatschappij as Platenmaatschappij, Ar_GeboorteDatum as Geboortedatum FROM tblArtiest", MyConnection)
DS = New DataSet()
MyCommand.Fill((DS), ("Artiesten"))
Return DS
'########################R1
End Function
Public Sub UpdateArtiesten(ByVal Update_DS As DataSet)
'##############################R1
MyConnection.Open()
Debug.WriteLine("Connectie: " & MyConnection.State)
'Here the changes i made to the dataset are stil there
'but the update does not work??????
MyCommand.Update(Update_DS, "Artiesten")
MyConnection.Close()
'################################R1
'print test on debug screen
Dim myRowtest As DataRow
Dim a As Integer
For Each myRowtest In Update_DS.Tables("Artiesten").Rows
Debug.WriteLine(myRowtest("Artiestnaam") & " " & myRowtest("PLatenmaatschappij") & " " & myRowtest("Geboortedatum"))
Next
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|