Datasets Are Making Me BALD !!! Please help me keep my hair

  • Thread starter Thread starter Terry Burns
  • Start date Start date
T

Terry Burns

I'm new to ADO.NET and I am trying to understand a problem.

I have a access table which is contained

PersonIndex
EventType

I created Connection, DataAdapter and dataset which is bound to my data
grid. It wont build an Update or Delete command because it cannot identify
the rows uniquely. OK, so then I add an auto number primnary key feild to
the access table and re-generate the dataset, now I have

PersonIndex
EventType
ID

Each time I fill the dataset, the ID's change ( increment ) which seems
nonsense to me. Also, if I delete rows and then update the dataadapter, no
error occurs but the rows are not erased, nor can you update the rows.

Can anyone shed any light on this ?
 
I would recommend staying away from the wizard, and writing this code by
hand. Then you won't have these problems.
 
I am not sure what is causing your anomaly. If the PK of a row is '15' in
the database, it should always be '15' in your dataset.

I myself prefer GUID's, because for inserting purposes, etc, they are
easier to use since you can create them on the client, and still know they
will be unique.

I recommend you start one step at a time. First figure out how to fill your
dataset in code. Then start learning about tools available to do
updates/inserts/deletes.

Since you haven't posted the relevant code, it is really hard to say what
the problem is just from your summary. But in general, I recommend you not
use the wizard. Not only will you learn a great amount, you will know
exactly what code is there and what it's doing - because you would have
written it yourself. There are tons of ADO.NET examples online to get you
started.
 
OK, Point taken. Thanks




Marina said:
I am not sure what is causing your anomaly. If the PK of a row is '15' in
the database, it should always be '15' in your dataset.

I myself prefer GUID's, because for inserting purposes, etc, they are
easier to use since you can create them on the client, and still know they
will be unique.

I recommend you start one step at a time. First figure out how to fill your
dataset in code. Then start learning about tools available to do
updates/inserts/deletes.

Since you haven't posted the relevant code, it is really hard to say what
the problem is just from your summary. But in general, I recommend you not
use the wizard. Not only will you learn a great amount, you will know
exactly what code is there and what it's doing - because you would have
written it yourself. There are tons of ADO.NET examples online to get you
started.
 
if I disable the cmd lines, the ID's correspond, else they start with 0 and
build and seem unique within the dataset.



peopleadapter.Fill(DsPeople1)

DsEvents1.Clear()

Dim cmd As New OleDb.OleDbCommand("SELECT personIndex,EventType FROM Events
where PersonIndex=@id", dnCon)

cmd.Parameters.Add("@ID", DataGrid1.Item(0, 0))

daEvents.SelectCommand = cmd

daEvents.Fill(DsEvents1)
 
I am not following at all. I don't understand what you are enabling or
disabling.

You don't seem to be retrieving the primary key column (which you said was
called ID) here.

As I said before, I prefer using GUID's.
 
Terry

Unless you really really need a Dataset object, why dont you just use one
table.

Also, lets make life easier and not use the wizard... don't worry, its
easier to learn this way.

Dim Conn as New OleDBConnection("connectStringGoesHere") ---- Or, use the
wizard just to make your connection object)

Dim DA as New OleDBDataAdapter("select * from YOURTABLENAME", Conn)
Dim DT as New DataTable

Now, you can do a DA.Fill(DT)

DT now has all of your stuff in it.

Let me know if this helps, or if u really do need a dataset. Also building
insert/update commands manually with parameters is really easy too.

Bob J.
 
Bob,
Thanx for your reply. I have coded this up manually now and still
get the same result. For some unknown reason, the PKey on my access table is
not brought over when using a paramaterised query.

this selects events associated with a person such as a birthday or
aniversary. so when the cell is chnaged on the datagrid which contains the
people it pickes up there ID and selects associated events by using the
add.parameter(@id . . . . etc

select * from events where @id = id

the result is that we do populate the events dg properly, but the id field
generates new unique numbers. I think its some anomaly which i dont
understand
 
Back
Top