473,671 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Remove Empty rows in datatable

94 New Member
Hi all,
I am importing data from excel sheet. i get the data in a datatable. when there are empty rows in excel i am getting empty rows in datatable also. how to remove empty rows? help me please.

Thanks & Regards
Aug 18 '07 #1
4 20385
kenobewan
4,871 Recognized Expert Specialist
How are you writing the rows? Probably easier to not write them. HTH.
Aug 18 '07 #2
sudhaMurugesan
94 New Member
How are you writing the rows? Probably easier to not write them. HTH.
I am getting data from excel sheet rows into a data table and then binding this dt to gridview.But empty rows making my gridview filled unnecessarily and running to pages. dt.rows.removea t option is there to remove rows but how i find the rowindex of the beginning of empty rows? this is my problem.
Aug 20 '07 #3
dip_developer
648 Recognized Expert Contributor
I am getting data from excel sheet rows into a data table and then binding this dt to gridview.But empty rows making my gridview filled unnecessarily and running to pages. dt.rows.removea t option is there to remove rows but how i find the rowindex of the beginning of empty rows? this is my problem.

probably you can make a dataview from your dataTable and filter out those empty rows before binding the table to gridview.....

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim dv As DataView
  3.    dv = New DataView
  4.    With dv
  5.       .Table = myDatatable
  6.       .AllowDelete = True
  7.       .AllowEdit = True
  8.       .AllowNew = True
  9.       .RowFilter = "myField = ' '"
  10.  End With
  11.  
Aug 20 '07 #4
sudhaMurugesan
94 New Member
probably you can make a dataview from your dataTable and filter out those empty rows before binding the table to gridview.....

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim dv As DataView
  3.    dv = New DataView
  4.    With dv
  5.       .Table = myDatatable
  6.       .AllowDelete = True
  7.       .AllowEdit = True
  8.       .AllowNew = True
  9.       .RowFilter = "myField = ' '"
  10.  End With
  11.  
Expand|Select|Wrap|Line Numbers
  1.  //dtExcel is datatable with empty rows
  2.        bool result = false;
  3.        int counter = 0;
  4.        int length = dtExcel.Rows.Count;
  5.        for (int j = 0; j < length;j++)
  6.        {
  7.  
  8.            DataRow dr = dtExcel.Rows[j];
  9.            if(result == false)
  10.            {
  11.             counter = 0;
  12.                for (int i = 0; i < dtExcel.Columns.Count; i++)
  13.                {
  14.                    result = dr.IsNull(dtExcel.Columns[i]);
  15.                    if (result == true)
  16.                    {
  17.                        counter = counter + 1;
  18.                        if (counter != 16)  //  i hav only 16 columns
  19.                        {
  20.                            result = false;
  21.                        }
  22.                    }
  23.                }
  24.            }
  25.            if (result == true && counter == 16)
  26.            {
  27.                //int index = dtExcel.Rows.IndexOf(j);
  28.                do
  29.                {
  30.                    dtExcel.Rows.RemoveAt(j);
  31.                } while ((dtExcel.Rows.Count - j) != 0);
  32.                break;   
  33.            }         
  34.    }
  35.         gvEmployeeImport.DataSource = dtExcel;
  36.         gvEmployeeImport.DataBind();
Thanks dip. i've used the above code to finish that task since i have to loop thro' each dr to import it to sql for which i need to remove blank rows. In your code i can only bind data to gridview without blank rows.Any way i knew code optimization is not achieved in mine. I try to use ur code in future.Thank you
Aug 20 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
23498
by: ted | last post by:
I'm having trouble using the re module to remove empty lines in a file. Here's what I thought would work, but it doesn't: import re f = open("old_site/index.html") for line in f: line = re.sub(r'^\s+$|\n', '', line) print line
3
2157
by: terragrub | last post by:
I found some code that works great to creat empty rows of boxes on a report from the end of the data to the bottom of the report. Now, I can't seem to find the original message to post a question on that thread. The code is as follows. In the Report OnFormat section the I use the following. Private Sub Report_Page()
3
4644
by: Baren | last post by:
Hi! I am developing a web project using ASP.NET and VB.NET as code behind. In one page the user attaches files to the list. The same data is shown in the and the max records visible is 4. Now the problem is I need to show 4 empty rows in the datagrid before binding the datagrid to the datasource. Can anyone help in this regard. Thanks in advance,
1
3417
by: lgalumbres | last post by:
Hi, I have a datagrid on Winform that is bound to a datatable. In essence, what I would like to do is that when a user inputs a number into a textbox control for example 5 then 5 empty rows will appear in the datagrid. any ideas? Im fairly new to vb.net and Ive been reading that manipulating a bound
1
4351
by: adarshmuneshwar | last post by:
How To Add Empty Rows In Grid View Control In Asp.net 2.0
5
4904
by: ramab | last post by:
hi guys, I can't figure out how to solve this problem. I have got 3 tab pages containing 3 datasheets based only 1 table. i have 3 primary keys in the table.Two primary keys are found in the 3 datasheets. My last primary key has an auto generated number. when i enter data in the 1st datasheet, for e.g when i filled in the first two rows, and then afterwards i filled my next datasheet, i will need to enter data on the third row. the first two...
2
16962
code green
by: code green | last post by:
I am trying to skip empty rows in a csv file The manual states But none of these tests seem to work. Anybody know why while(($data = fgetcsv($this->handle)) !== false) { if(!is_null($data)) #no if(!empty($data)) #no if(!empty($data)) #no { And variations thereof
36
9158
by: laredotornado | last post by:
Hi, I'm using PHP 5. I have an array of strings. What is the simplest way to remove the elements that are empty, i.e. where the expression "empty($elt)" returns true? Thanks, - Dave
1
4454
by: premMS143 | last post by:
Hi 1 & all, Using VB, How to remove blank rows in a Excel worksheet? For example, I'm having a Excel sheet containing 900 rows data, in which there are blank rows inserted in between. Manually I deleted 450 rows & is there any way to do this using VB? Please guide me. Thanx & regards, Prem
0
8392
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8912
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8597
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8669
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4403
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2049
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.