Re: How to insert row in typed dataset by RobinS
RobinS
Sat Jan 27 01:29:46 CST 2007
I agree about setting the autoincrement settings to -1. But
if he's using a strongly typed dataset, calling Update on the table
adapter should automatically check the rowstate and insert the new
ones if the rowstate is Added.
I don't understand the use of ResetCurrentItem on the binding source.
I haven't found a need to use that. Can you explain that a bit?
I agree about the ADO.net books. I use Sceppa's book a lot.
Robin S.
-------------------------------------------------
"Earl" <brikshoe@newsgroups.nospam> wrote in message
news:%23HHGjIbQHHA.1016@TK2MSFTNGP04.phx.gbl...
> The best technique I've seen is to set your dataset PKs to negative
> seed and increment (-1). I then use that value as a decision point as
> to whether to create a new row or update the existing.
>
> Obviously you have to AddNew on your bindingsource in order to add a
> new row to the table. You do that before you populate the new row.
> Then just as you EndEdit and Update, you do the same for your new rows
> (I actually do both within the same method, then branch out depending
> upon which function I'm performing). You must also call
> ResetCurrentItem on the bindingsource. This is all shown well in the
> recent ADO.Net 2.0 books on the market (see the ones by Vaughn, Malik,
> or Sceppa).
>
> BindingSource.ResetCurrentItem()
> eBindingSource.EndEdit()
>
> "Benson" <bensonwyl@yahoo.com.hk> wrote in message
> news:%23z6%23ZZSQHHA.1200@TK2MSFTNGP02.phx.gbl...
>>I create a typed dataset by drag'n'drop in VS2005 (VB). I can use
>>FillBy or GetDataBy methods to retrieve the record. The code is as
>>follows:
>>
>> dataTable = tableAdapter.GetDataByCode(KeyFieldValue)
>> MtrUnitBindingSource.DataSource = dataTable
>> 'user edits the record
>> 'press ok button to save
>> MtrUnitBindingSource.EndEdit()
>> tableAdapter.Update(dataTable)
>> ==> it works perfectly in find/edit/update mode.
>> Question:
>> 1. I find difficulty in New/Insert mode. How to add a new row and do
>> the insert to the database?
>> 2. If in the view mode (only user views the record), how to set
>> datatable to readonly?
>>
>> Benson
>> VB2005
>>
>
>