locked
Index Out of Range RRS feed

  • Question

  • Hello when i get data from grid into textboxes and i wanna editi primary key it give s me this exception , IndexOut Of Range and here is my Editing code , keep in mind this work fine for other attribute but primary key no??

    •       Dim OrderRow() As Data.DataRow
    •         OrderRow = DataSet1.Tables("Ordertest").Select("orderID = '" + TxtAdd1.Text + "'")
    •         ' OrderRow(0)("orderID") = TxtAdd1.Text
    •         OrderRow(0)("restaurantName") = TxtAdd2.Text
    •         OrderRow(0)("RestaurantArea") = TxtAdd3.Text
    •         OrderRow(0)("BranchId") = TxtAdd4.Text
    •         OrderRow(0)("OrderTime") = TxtAdd5.Text
    •         OrderRow(0)("OrderDate") = TxtAdd6.Text
    •         OrderRow(0)("EndTime") = TxtAdd7.Text
    •         OrderRow(0)("Restaurant") = TxtAdd8.Text
    •         OrderRow(0)("OrderStatus") = TxtAdd9.Text
    •         OrderRow(0)("OrderType") = TxtAdd10.Text
    •         ' testGridView.Refresh()
    •     End Sub

    Tuesday, October 4, 2011 6:31 AM

Answers

  • If you can change the table layout, create a new column with the same properties like the orderID column.
    Then play something with the properties. For example set the primary key to the new column or allow a NULL value to the column.
    After that modify your application with the new column and test it.

    I have no example, so I can't test this...

     


    • Edited by Marco Pangritz Wednesday, October 5, 2011 7:19 AM
    • Marked as answer by computact Tuesday, October 18, 2011 5:03 AM
    Wednesday, October 5, 2011 7:19 AM

All replies

  • Are you sure, that the column is in the result?
    Tuesday, October 4, 2011 6:49 AM
  • yes and to be specific it gives me this "Index was outside the bounds of the array."

    in this assignment OrderRow(0)("orderID") = TxtAdd1.Text, but this only when i want to edit the first textbox which represent primary key

    Tuesday, October 4, 2011 6:59 AM
  • When I tested this example and playing with the primarykey property, I've got no error.

    http://msdn.microsoft.com/en-us/library/system.data.datarow(v=vs.71).aspx

    The index out of range tells me, that the column not exists in the result...

    For testing, can you get data from a datasource, so you can show the content of the column in a datagrid?

     

     


    Tuesday, October 4, 2011 7:18 AM
  • yes i do show my column in datagrid
    Tuesday, October 4, 2011 7:28 AM
  • What type of datasource have you bound to the datagrid?
    If it's a database, can you post the column attributes in the db?

     

    Tuesday, October 4, 2011 7:34 AM
  • yes it s database and here is my table
    Tuesday, October 4, 2011 7:40 AM
  • Are you sure that orderId is editable? It is not identity?
    Tuesday, October 4, 2011 7:48 AM
  • what do you mean how can I check this 
    Tuesday, October 4, 2011 8:19 AM
  • You can check this in the database, column definition.
    What type of db do you run?

    Tuesday, October 4, 2011 8:38 AM
  • sql server
    Tuesday, October 4, 2011 8:38 AM
  • and i have checked and it is in identity = No

    so ????

    Tuesday, October 4, 2011 8:40 AM
  • Can you post the definition of the column? Data type, indexes...
    Tuesday, October 4, 2011 8:48 AM
  • here is it 
    Tuesday, October 4, 2011 8:57 AM
  • It seems everthing ok...
    Is there an inner exception, which displays an exacter error message?
    Tuesday, October 4, 2011 9:09 AM
  • hmm what do you mean
    Tuesday, October 4, 2011 9:16 AM
  • You can show details of the exception, when you debug the error.
    One property is the inner exception...
    Tuesday, October 4, 2011 9:32 AM
  • ok here is the exception error
    • Edited by computact Wednesday, October 5, 2011 4:45 AM Duplicate
    Wednesday, October 5, 2011 4:44 AM
  • If you click on Actions: View Detail... maybee you can see the inner exception!
    That was the question...
    Wednesday, October 5, 2011 6:15 AM
  • yes inner exception is set to nothing so

    thanks

    Wednesday, October 5, 2011 7:08 AM
  • If you can change the table layout, create a new column with the same properties like the orderID column.
    Then play something with the properties. For example set the primary key to the new column or allow a NULL value to the column.
    After that modify your application with the new column and test it.

    I have no example, so I can't test this...

     


    • Edited by Marco Pangritz Wednesday, October 5, 2011 7:19 AM
    • Marked as answer by computact Tuesday, October 18, 2011 5:03 AM
    Wednesday, October 5, 2011 7:19 AM
  • Hi computact,

    How about your concern?

     

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, October 18, 2011 2:43 AM