vb try to skip some data while reading?? [urgent]
-
i haveing an error while running my coding which is to pass the info from the data grid to EXCEL... it pass correctly at first but when it try to pass the last 3 row then error pops up : Runtime error '6148' invalid row number. when i try to check my excel the last print out b4 error happen,it refer to the data grid last row info which mean it try to skip to the last row... so when the system try to read next time there was no more line to read... i have check my code many time i dunno y the vb just skip the line itself.... For example again: datagrid row 10 = EXCEL row 10 but the EXCEL row 10 have print out datagrid row 20...
i = 3 'ROW j = 2 'Column For dr = 0 To (Adodc1.Recordset.RecordCount - 1) For dc = 0 To (DataGrid1.Columns.Count - 1) DataGrid1.Row = dr DataGrid1.Col = dc ApExcel.Cells(i + 1, j).Value = DataGrid1.Text 'Pass info from data grid to EXCEL j = j + 1 Next dc j = 2 i = i + 1 Next dr
-
i haveing an error while running my coding which is to pass the info from the data grid to EXCEL... it pass correctly at first but when it try to pass the last 3 row then error pops up : Runtime error '6148' invalid row number. when i try to check my excel the last print out b4 error happen,it refer to the data grid last row info which mean it try to skip to the last row... so when the system try to read next time there was no more line to read... i have check my code many time i dunno y the vb just skip the line itself.... For example again: datagrid row 10 = EXCEL row 10 but the EXCEL row 10 have print out datagrid row 20...
i = 3 'ROW j = 2 'Column For dr = 0 To (Adodc1.Recordset.RecordCount - 1) For dc = 0 To (DataGrid1.Columns.Count - 1) DataGrid1.Row = dr DataGrid1.Col = dc ApExcel.Cells(i + 1, j).Value = DataGrid1.Text 'Pass info from data grid to EXCEL j = j + 1 Next dc j = 2 i = i + 1 Next dr
use :- For dr = 0 To (Adodc1.Recordset.RecordCount - 1) For dc = 0 To (DataGrid1.Columns.Count - 1) DataGrid1.Row = dr+1 ' as 0 is not a valid row
IT IS NOT AS IMPORTANT AS WHETHER YOU SUCCEED OR FAIL BUT WHAT IMPORTANT IS THAT YOU TRY YOUR BEST. SO ALWAYS TRY AT YOUR LEVEL BEST
-
use :- For dr = 0 To (Adodc1.Recordset.RecordCount - 1) For dc = 0 To (DataGrid1.Columns.Count - 1) DataGrid1.Row = dr+1 ' as 0 is not a valid row
IT IS NOT AS IMPORTANT AS WHETHER YOU SUCCEED OR FAIL BUT WHAT IMPORTANT IS THAT YOU TRY YOUR BEST. SO ALWAYS TRY AT YOUR LEVEL BEST
i run ok for the 0 which mean the first line. when it go to the 11 line then something goes wrong with the data it will get the last value of the data. u know wat i mean? when it get the last data of the last row but which is not. when it go to the next row, there is nothing to get so error came out. But i didnt control the VB to skip the 11 line...
-
i haveing an error while running my coding which is to pass the info from the data grid to EXCEL... it pass correctly at first but when it try to pass the last 3 row then error pops up : Runtime error '6148' invalid row number. when i try to check my excel the last print out b4 error happen,it refer to the data grid last row info which mean it try to skip to the last row... so when the system try to read next time there was no more line to read... i have check my code many time i dunno y the vb just skip the line itself.... For example again: datagrid row 10 = EXCEL row 10 but the EXCEL row 10 have print out datagrid row 20...
i = 3 'ROW j = 2 'Column For dr = 0 To (Adodc1.Recordset.RecordCount - 1) For dc = 0 To (DataGrid1.Columns.Count - 1) DataGrid1.Row = dr DataGrid1.Col = dc ApExcel.Cells(i + 1, j).Value = DataGrid1.Text 'Pass info from data grid to EXCEL j = j + 1 Next dc j = 2 i = i + 1 Next dr
campbells wrote:
For dr = 0 To (Adodc1.Recordset.RecordCount - 1) For dc = 0 To (DataGrid1.Columns.Count - 1) DataGrid1.Row = dr
I am not entirely sure I understand your problem, but should not you put the line "DataGrid1.Row = dr" between "For dr = 0 To (Adodc1.Recordset.RecordCount - 1)" AND For dc = 0 To (DataGrid1.Columns.Count - 1)" so that the row is changed after all the columns are processed? Hope this helps.
Shreekar http://shreekarishere.blogspot.com
-
i run ok for the 0 which mean the first line. when it go to the 11 line then something goes wrong with the data it will get the last value of the data. u know wat i mean? when it get the last data of the last row but which is not. when it go to the next row, there is nothing to get so error came out. But i didnt control the VB to skip the 11 line...
on which line and text error occurs ? either datagrid1.text or other ? IT IS NOT AS IMPORTANT AS WHETHER YOU SUCCEED OR FAIL BUT WHAT IMPORTANT IS THAT YOU TRY YOUR BEST. SO ALWAYS TRY AT YOUR LEVEL BEST
-
on which line and text error occurs ? either datagrid1.text or other ? IT IS NOT AS IMPORTANT AS WHETHER YOU SUCCEED OR FAIL BUT WHAT IMPORTANT IS THAT YOU TRY YOUR BEST. SO ALWAYS TRY AT YOUR LEVEL BEST
the code which i have underline it. I know y there is an error because when i read there is no more information cause it have skip to the last line which i did not ask it to do so... so i not sure happen with the system.... when i run the system i check one by one... example, suppose it will pass 14 row with 5 column information each of it. when it goes to row 12, then the first 2 colum data which is not the correct one the vb itself have skip to row 13-14 and get the value. after that sure it will have error becasue when it try to read the row 13, but the arrow have been point to the last 14 row b4 when it put the value to row 12, so the next data will be 15 which is an empty one.
-
campbells wrote:
For dr = 0 To (Adodc1.Recordset.RecordCount - 1) For dc = 0 To (DataGrid1.Columns.Count - 1) DataGrid1.Row = dr
I am not entirely sure I understand your problem, but should not you put the line "DataGrid1.Row = dr" between "For dr = 0 To (Adodc1.Recordset.RecordCount - 1)" AND For dc = 0 To (DataGrid1.Columns.Count - 1)" so that the row is changed after all the columns are processed? Hope this helps.
Shreekar http://shreekarishere.blogspot.com
at first the DR which mean the row~ since i'm showing the data in the datagrid first, then pass to EXCEL. DC which is the column , which there is 5 column. when goes to row 1, then pass the datagrid column data to excel, after passing the row 1 column data, then next dr which is ROW 2.
-
at first the DR which mean the row~ since i'm showing the data in the datagrid first, then pass to EXCEL. DC which is the column , which there is 5 column. when goes to row 1, then pass the datagrid column data to excel, after passing the row 1 column data, then next dr which is ROW 2.
try this for dr =0 to datagrid1.rows-1 IT IS NOT AS IMPORTANT AS WHETHER YOU SUCCEED OR FAIL BUT WHAT IMPORTANT IS THAT YOU TRY YOUR BEST. SO ALWAYS TRY AT YOUR LEVEL BEST
-
try this for dr =0 to datagrid1.rows-1 IT IS NOT AS IMPORTANT AS WHETHER YOU SUCCEED OR FAIL BUT WHAT IMPORTANT IS THAT YOU TRY YOUR BEST. SO ALWAYS TRY AT YOUR LEVEL BEST
-
i m so sorry for dr =0 to datagrid1.rows-1
IT IS NOT AS IMPORTANT AS WHETHER YOU SUCCEED OR FAIL BUT WHAT IMPORTANT IS THAT YOU TRY YOUR BEST. SO ALWAYS TRY AT YOUR LEVEL BEST
-
i haveing an error while running my coding which is to pass the info from the data grid to EXCEL... it pass correctly at first but when it try to pass the last 3 row then error pops up : Runtime error '6148' invalid row number. when i try to check my excel the last print out b4 error happen,it refer to the data grid last row info which mean it try to skip to the last row... so when the system try to read next time there was no more line to read... i have check my code many time i dunno y the vb just skip the line itself.... For example again: datagrid row 10 = EXCEL row 10 but the EXCEL row 10 have print out datagrid row 20...
i = 3 'ROW j = 2 'Column For dr = 0 To (Adodc1.Recordset.RecordCount - 1) For dc = 0 To (DataGrid1.Columns.Count - 1) DataGrid1.Row = dr DataGrid1.Col = dc ApExcel.Cells(i + 1, j).Value = DataGrid1.Text 'Pass info from data grid to EXCEL j = j + 1 Next dc j = 2 i = i + 1 Next dr
The problem is that your assuming that a DataGrid row is the same as a Row in the Dataset. It's not. You shouldn't even be getting the data out of the DataGrid. Just use the RecordSet object as your source of data to copy to the Excel sheet. The DataGrid is just for showing and editing what's in the RecordSet, keep it that way. Now, since you're using VB.NET, why are you using the old ADODB objects when the .NET Framework provides much better and easier to use DataSet classes?
Dave Kreskowiak Microsoft MVP - Visual Basic