Click here to Skip to main content
13,143,185 members (35,025 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Greetings all,
I have an sql table and I would like to delete all empty rows from the the table.
Any help?

What I have tried:

protected void DeleteEmptyRow()
        {
 
           
                SqlConnection connection1 = new SqlConnection(@"Data Source=CEn-PC\SQLEXPRESS;Initial Catalog=UserData;Integrated Security=True");
                SqlDataAdapter adapter = new SqlDataAdapter("SELECT *FROM AuditReport", connection1);
                DataTable dt = new DataTable();
                adapter.Fill(dt);
 
            for (int i = dt.Rows.Count - 1; i >= 0; i--)
            {
                DataRow row = dt.Rows[i];
                SqlCommand sqlComm1 = new SqlCommand(@"DELETE FROM AuditReport WHERE '" + row[0] + " like "+null+"'", connection1);
            }
 
            for (int i = dt.Rows.Count - 1; i >= 0; i--)
            {
                DataRow row = dt.Rows[i];
                SqlCommand sqlComm1 = new SqlCommand(@"DELETE FROM AuditReport WHERE '" + row[0] + " like " + string.IsNullOrEmpty(row[0].ToString()) + "'", connection1);
            }
 
        }
Posted 13-Sep-17 5:32am
calibio421
Updated 13-Sep-17 7:27am
CPallini408K
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

DELETE FROM AuditReport WHERE myColumn IS NULL OR trim(myColumn) = '';
  Permalink  
Comments
calibio 14-Sep-17 6:46am
   
Thank you @RickZeeland , it worked perfectly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 13 Sep 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100