I need your help. Please help me.
I am very surprise of this error message:
Index was out of range. Must be non-negative and less thatnt he size of the collection. Parameter name :Index
I am using C#NET2008 and try to retrieve data from the Clicked Row and it’s not working to my surprised. It has not happened before. This particular problems is because the SQL String retrieve 13 data columns from SQL SERVER Table to fill the DataGridView for display.
This coding : string strHomePage = (string) this.DGVSupplier.CurrentRow.Cells[11].Value;
Generated the error message:
This is the SQL String which retrieve data from SQL SERVER to fill DataGridView DataSource via DataSet
string strSql = "SELECT SupplierID, CompanyName, ContactName, "
+ "ContactTitle, Address, City, Region, PostalCode, "
+ " Country, Phone, Fax, HomePage "
+ "FROM TBLSuppliers "
+ "ORDER BY SupplierID";
Expand|Select|Wrap|Line Numbers
- private void DGVSupplier_Click(object sender, EventArgs e)
- {
- int intSuppId = (int) this.DGVSupplier.CurrentRow.Cells[0].Value;
- string strCompName = (string) this.DGVSupplier.CurrentRow.Cells[1].Value;
- string strContName = (string) this.DGVSupplier.CurrentRow.Cells[2].Value;
- string strContTitle = (string) this.DGVSupplier.CurrentRow.Cells[3].Value;
- string strAddr = (string) this.DGVSupplier.CurrentRow.Cells[4].Value;
- string strCity = (string) this.DGVSupplier.CurrentRow.Cells[5].Value;
- string strRegion = (string) this.DGVSupplier.CurrentRow.Cells[6].Value;
- string strPostCode = (string) this.DGVSupplier.CurrentRow.Cells[7].Value;
- string strCountry = (string) this.DGVSupplier.CurrentRow.Cells[8].Value;
- string strPhone = (string) this.DGVSupplier.CurrentRow.Cells[9].Value;
- string strFax = (string) this.DGVSupplier.CurrentRow.Cells[10].Value;
- string strHomePage = (string) this.DGVSupplier.CurrentRow.Cells[11].Value; <---- Error here
- }
Please help me. Thank you very much