'IndexOutOfRangeException was unhandled' ??

Database1DataSet myInstance = new Database1DataSet();

object Timo = myInstance.Tables["Table1"].Rows[0].ItemArray[0];

so this is my code (still :p) but it says 'IndexOutOfRangeException was unhandled' but why does it say that error its not under 0, the number is 0 so is the first row (cant be too high), and what do they mean with: 'Make sure data column names are correct' where do I need to type data column names

pls help me :<

thx in advance



Answer this question

'IndexOutOfRangeException was unhandled' ??

  • Gy&amp;#240;a

    I have this:

    private void Form1_Load(object sender, EventArgs e)

    {

    this.table1TableAdapter.Fill(this.database1DataSet.Table1);

    }


  • Iggy2

    I'm trying to change data of a specific row, I think I'm getting my data from my dataset :x
  • oman

    Hi,

    I'm guessing your table has no column, or, more likely, your data table has no rows. In you're code, you're assuming both - that your table has at least one column (that's probably true) and that it contains at least one row (that might not be so). Before executing the above line, test for row (and/or) column presence, like:

    if (myInstance.Tables["Table1"].Rows.Count > 0)
    {
    object Timo = myInstance.Tables["Table1"].Rows[0].ItemArray[0];
    }
    else
    {
    // no rows...
    }

    Andrej



  • Kamii47

    Ok. so you probably have some code where you're reading that data from the database table into your dataset Like, using table adapters to fill your dataset (myTableAdapter.Fill(myDataSet.MyDataTable)

    Can you check if your data gets loaded properly into your local dataset

    Andrej



  • MuscleHead

    RubenPieters wrote:
    ...but was is ment then by rows(I thought rows where your rows in your table, but I have rows in my table) ...

    Sorry, didn't quite understand this one...

    About adding rows... you can add rows manually (see ...Rows.Add method), or more common practice - get them from some database.

    Andrej



  • Teo Lachev

    Andrej Tozon wrote:

    May i suggest some reading on data concepts in .NET framework Getting Started with Data Access page on MSDN is a good place to start...

    Andrej

    ok i prolly made the question to 'easy' with reading a bit I know now what rows are(they are what I thought they were ^^) but I am not missing any or not not having any at that number, so why does it say i dont have rows


  • mwoehlke

    ok thx, I have indeed no rows it seems, but was is ment then by rows(I thought rows where your rows in your table, but I have rows in my table) and where do I add them
  • Jakobdo

    there hasn't changed anything :/
  • BRCEWANE

    May i suggest some reading on data concepts in .NET framework Getting Started with Data Access page on MSDN is a good place to start...

    Andrej



  • J.Mathes

    well, I have a database with a table (and with data in it) but somehow it says there aren't rows in it...
  • MJWhiteman

    its easy... what are rows :x
  • CSharpShooter

    I don't see your code, but here's how these things work... You define a dataset, containing some datatables with columns. You have to fill these tables with data, e.g. fill them with data rows". You either do this by reading data from the database (SQL Server, etc.) or by manually adding rows to those tables. Once you have data tables filled with the data, you can start using that data. You can check whether specific tables have data or not by setting a breakpoint on some code line, dealing with datasets, and then hover your mouse cursor over dataset/datatable variable and select the little maginifying lense.

    Again, your code probably tries to access the first row (0) of your Table1. If your table has no rows in it, the row 0 doesn't exist in the data table and you get the IndexOutOfRangeException.

    Andrej



  • t_1369

    What exactly are you trying to do Where are you getting data from

    Andrej



  • gabriel_333

    That looks good. Now, try this:

    object Timo = this.database1DataSet.Table1.Rows[0].ItemArray[0];

    It's a variation of your code - it doesn't create a new dataset instance, but uses the table in the same dataset instance - Table1 should now be filled with the code line you posted. The complete code [note: I didn't include row count checking, as specified in one of the previous posts]:

    private void Form1_Load(object sender, EventArgs e)
    {
       
    this.table1TableAdapter.Fill(this
    .database1DataSet.Table1);
        object Timo = this.database1DataSet.Table1.Rows[0].ItemArray[0];
       
    // check Timo here
    }

    Andrej



  • 'IndexOutOfRangeException was unhandled' ??