Re: I can find it, why can't my code?
- From: "W.G. Ryan - MVP" <WilliamRyan@xxxxxxxxxxxxxxxx>
- Date: Tue, 18 Oct 2005 11:13:26 -0400
You create an Array of datacolumns (even if it's just one column) and then
set it accordingly. that's the right syntax, but here's an example i wrote
a while back that walks you through it
http://www.knowdotnet.com/articles/adopartiii.html
"PaulNaude" <PaulNaude@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1E099864-883E-48C2-A678-0151BEFEA548@xxxxxxxxxxxxxxxx
> Thank again!
>
> I didn't realise that is important to set up the primary keys on the .NET
> side as well! in all the other cases everything worked as intended. I will
> try this and let you know.
>
> PS: The book I have from Rick Dobson as well as the online help is very
> sketchy about how to set the primary key for a dataset table which exist
> in a
> db.
> Is it correct to use:
> dataset.table(0).primarykey = new datacolumn()
> {dataset.table(0).columns(0)
> dataset.table(0).columns(1) dataset.table(0).columns(2)}
>
> Regards
>
> "W.G. Ryan - MVP" wrote:
>
>> Paul - I know you've probably already checked this, but it should be
>> working. Just to be safe, you are sure that the PrimaryKey is defined on
>> the DataTable object as well as in the database (although it being in the
>> db
>> is not necessary). I only ask b/c you mention that PrimaryKey in the
>> database, but you must use the PK of the datatable as well. If not, you
>> get
>> erratic behavior. The fact that deleting it via the grid works is a
>> different issue b/c it's not running the same code, so when you delete
>> the
>> row, it knows the index of the datatable and deletes is accordingly.
>> Double
>> check the PrimaryKey property of the table (http://shrinkster.com/8rf )
>> [the datatable locally) just to be sure. If that matches what you
>> expect,
>> then this behavior is weird indeed - we'll take it from there if that's
>> the
>> case
>> "PaulNaude" <PaulNaude@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:0B03FCD0-E3BD-4657-98DA-856867BA8716@xxxxxxxxxxxxxxxx
>> >I have a problem deleting a record from a table with 3 primary keys, in
>> >code.
>> > I get the values of the primary keys from my datagrid displaying the
>> > record
>> > to be deleted as follows:
>> > ...
>> > findTheseVals(0) = DataGrid4.Item(u, 0) 'First column and unique
>> > primary
>> > key
>> > (no duplicates allowed)
>> > findTheseVals(1) = DataGrid4.Item(u, 1) 'Second column and primary key
>> > (duplicates ok)
>> > findTheseVals(2) = DataGrid4.Item(u, 2) 'Third column and primary key
>> > (duplicates ok)
>> > ...
>> >
>> > Then, to delete the record from the table, I use
>> >
>> > DataSet11.Tables("Equipment").Rows.Find(findTheseVals).Delete()
>> >
>> > but get the following error:
>> >
>> > An unhandled exception of type 'System.NullReferenceException' occurred
>> > in
>> > App.exe
>> > Additional information: Object reference not set to an instance of an
>> > object.
>> >
>> > i.e. this record was not found, although I can physically see it in the
>> > table.
>> >
>> > I checked the populated values of findTheseVals and it matches my
>> > primary
>> > key values (and types) in the database table exactly.
>> > The column orders in the dataAdapter, datagrid and database table are
>> > identical.
>> > I checked that the table referenced is exactly the same as the one
>> > referenced by the datagrid etc.
>> >
>> > When I manually delete the row from my datagrid, the record is
>> > correctly
>> > deleted from the database.
>> >
>> > What am I missing here?
>>
>>
>>
.
- Follow-Ups:
- Re: I can find it, why can't my code?
- From: PaulNaude
- Re: I can find it, why can't my code?
- References:
- Re: I can find it, why can't my code?
- From: PaulNaude
- Re: I can find it, why can't my code?
- Prev by Date: Re: Force update datagrid
- Next by Date: Recover from NullReferenceException in OracleClient.DBObjectPool...
- Previous by thread: Re: I can find it, why can't my code?
- Next by thread: Re: I can find it, why can't my code?
- Index(es):
Relevant Pages
|