but in code page i cannot seem to update messages table through Dataview source code:
Dim dv As DataView = CType(SqlCorrespondance.Select(DataSourceSelectArguments.Empty), DataView)
If Not dv Is Nothing Then
dv.AllowNew = True
Dim newRow As DataRowView = dv.AddNew()
newRow.BeginEdit()
newRow.Item("PRODUCTID") = ProdID
newRow.Item("RefItemID") = RefItemID
newRow.Item("MessageID_Reply") = MessageID.Value
newRow.Item("subject") = lblSubject.Text
newRow.Item("body") = Server.HtmlDecode(TxtReply.Text)
newRow.Item("datentime") = Date.Now
newRow.EndEdit()
End If
RepCorrespondance.DataSource = dv
If there is no error in your codes, the only possible reason is that you forget to call DataBind() method for the repeater control.
Add the below line of codes after the DataSource line
RepCorrespondance.DataSource = dv
RepCorrespondance.DataBind()
I tested your codes and could not understand the rationale of your design.
You don't store the new row into the database? Just directly display it?
The common implementation would be inserting the new row to the database and then select the updated result from database and bind the data to the controls.
Could you please check if you need to modify the current codes?
Hope helps.
Best regards,
Sean
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
it just displays the data in the bound repeater control?
The DataView is a UI construct used to present different "data views" of an in memory DataTable . For example, sorting. The DataView is disconnected from the data store.
peterthegreat
What purpose does it then serve or where else does it serve?
Member
288 Points
886 Posts
SQL DataView will not update records?
Oct 18, 2020 02:19 PM|peterthegreat|LINK
i have declared SQLdatasource as such:
but in code page i cannot seem to update messages table through Dataview source code:
Contributor
2890 Points
847 Posts
Re: SQL DataView will not update records?
Oct 19, 2020 03:42 AM|Sean Fang|LINK
Hi peterthegreat,
If there is no error in your codes, the only possible reason is that you forget to call DataBind() method for the repeater control.
Add the below line of codes after the DataSource line
RepCorrespondance.DataSource = dv RepCorrespondance.DataBind()
I tested your codes and could not understand the rationale of your design.
You don't store the new row into the database? Just directly display it?
The common implementation would be inserting the new row to the database and then select the updated result from database and bind the data to the controls.
Could you please check if you need to modify the current codes?
Hope helps.
Best regards,
Sean
Member
288 Points
886 Posts
Re: SQL DataView will not update records?
Oct 22, 2020 01:41 PM|peterthegreat|LINK
i have not used this method before and presumed it would update database automatically?
So do i need to include insert statements to my SQLDatasource object wizard for it to work?
Thanks
Contributor
2890 Points
847 Posts
Re: SQL DataView will not update records?
Oct 23, 2020 09:58 AM|Sean Fang|LINK
Hi peterthegreat,
You definitely should use this method as long as you want to bind data to the data control.
It does nothing about database but only deal with the data binding for the contorls.
You could refer to this link:
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.repeater.databind?view=netframework-4.8
Hope helps.
Best regards,
Sean
Member
288 Points
886 Posts
Re: SQL DataView will not update records?
Oct 23, 2020 01:58 PM|peterthegreat|LINK
So, the database table will not be updated with the values added?
it just displays the data in the bound repeater control?
What purpose does it then serve or where else does it serve?
All-Star
53051 Points
23629 Posts
Re: SQL DataView will not update records?
Oct 23, 2020 02:38 PM|mgebhard|LINK
Correct. Database tables are not affected by updating a DataView.
In ADO.NET, the DataAdapter is used to update a data source.
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/updating-data-sources-with-dataadapters
The DataView is a UI construct used to present different "data views" of an in memory DataTable . For example, sorting. The DataView is disconnected from the data store.
Please see the DataView reference documentation.
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/dataset-datatable-dataview/dataviews