Another Dataset Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi ther
First off, sorry for this long post, but I think it is needed to explain my proble

I have this dataset I am working with named dsMyDataset I am trying to add data to the dataset/ access database in the following manner

Dim arMyLines As DataRow = dsMyDataset.MyRecords.NewRo

odcMyConnection.Open(

Dim holdNumber As Intege

holdNumber = dsMyDataset.Tables("MyRecords").Rows.Count +

Tr

arMyLines ("Number") = holdNumbe

arMyLines ("Date") = CDate(Label1.Text

arMyLines ("Home") = TextBox1.Tex

arMyLines ("Away") = TextBox2.Tex

dsMyDataset.Tables("MyRecords").Rows.Add(arMyLines

odaMyAdapter.Update(dsMyDataset

Catc
arMyLines.Delete(

dsMyDataset.Clear(

End Tr

odcMyConnection.Close()

What I am trying to do is count the number of rows in the dataset/database, add 1 to it and put that number under the “Number†column in the database along wit the other row dat

holdNumber always contain the number 1 and the “TRY†throws an error saying, in not so many words, I have two of the same records

I removed all the primary keys in the dataset and the access database and still get the same error

I have setup the database exactly the way it is suppose to be

The problem is with the “Number†Column since I already have 1 in first row of the databas

For some reason holdNumber = dsMyDataset.Tables("MyRecords").Rows.Count is not counting the number of rows in the dataset/database. It always shows 0
So adding 1 to 0 gives you 1 and the "number" column already have a 1 (the first row) in i

Any ideas on how to solve this
Once again, sorry about the length of thi
 
Hi Sam,

Firstoff, can you next time first copy your code in a notepath and than copy
it back in the message, that makes it more readable for everybody.

Than about your problem first a question:
Do you have a primary key in your datarow and which is that?

What you can show us maybe as well is your fill, because I get the idea that
your dataset is never filled?

Cor
 
Hi Co
Let me say I thought that the code I posted was as clear as I could make it. If it was't, my apologie
Anyway, Thanks for the help
Your suggestion to first fill the dataset is doing exactly what I want by doing the following. It work

Dim holdNumber As Integer = 0
odcMyConnection.Open() 'Open Connectio
odaMyAdapter.Fill(dsMyDataset, "MyRecords") 'Fill datase
holdNumber = dsMyDataset.Tables("MyRecords").Rows.Count + 1 'Get and assign row count add
odcMyConnection.Open() 'Close Connectio

You want to hear something weird: At one time, I actually had this working without filling the dataset. That is strang
Thanks, again
 
Back
Top