c# - Refresh a strongly typed DataSet -
i have typed dataset calls stored procedures.in 1 case add data in database using typed data set.the data gets added database reason new data not being displayed.
this leads me believe have somehow refresh typed dataset after add new item.i not sure code should post here post code adds elements database:
var addbookadapter = new queriestableadapter(); addbookadapter.addbook(book.name,book.author,book.description,book.publicationdate,book.categoryid); this stored procedure this:
create procedure [dbo].[addbook] @name nvarchar(max), @author nvarchar(max), @description nvarchar(max), @date date , @categoryid int insert books (name , author , description , publicationdate , categoryid) values (@name , @author , @description , @date , @categoryid) as mentioned works.the new item gets added db not displayed
if underlying data in database has changed, way load information dataset load manually. have couple of options here, depending on needs:
- you can discard existing data , re-fill data set data adapter.
- you can load second copy of dataset , use
dataset.mergebring in changes. - you can add new row dataset directly.
however, when you're using typed data sets, intention use object when adding new rows, not add them database via table adapter. when add new row table in data set, tracked "added" in memory. when go save changes dataset database via table adapter, dataset call whatever appropriate insertcommand or updatecommand tables. in way, database , dataset synchronized.
the workflow using typed datasets typically has following steps, in order. can rather complex merge resolution logic , how handle conflicts, basic idea same:
dataadapter.fill(dataset)- (make changes typed dataset via typed data rows)
datachanges = dataset.getchanges()dataadapeter.update(datachanges)dataset.merge(datachanges)dataset.acceptchanges()
Comments
Post a Comment