1

I want to get specific colums to show on my C# WPF DataGrid.

I used this code to get selected columns:

using (SqlConnection con = new SqlConnection(ConString))
{
    SqlCommand cmd = new SqlCommand("SELECT roll FROM cmt_7th", con);
    SqlDataAdapter sda = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable("cmt_7th");
    sda.Fill(dt);
    MydataGrid_roll.ItemsSource = dt.DefaultView;
}

But I want to show only those row which column data is empty .

Like this

Left image is output screen short and right image is sql table image on "Like this" link image

I want to get rows 5 to 10 and ignore 1 to 4 row where all columns are not null.

1 Answer 1

3

According to your description, you want to get all row where name, department, phone are null. So, you have to apply condition in your sql. Please check this:

string ConString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(ConString))
{

    SqlCommand cmd = new SqlCommand("SELECT roll FROM cmt_7th WHERE name IS Null And department IS Null And phone IS Null", con);
    SqlDataAdapter sda = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable("cmt_7th");
    sda.Fill(dt);
    MydataGrid_roll.ItemsSource = dt.DefaultView;

}

Check this output of the SQL:

enter image description here

Sign up to request clarification or add additional context in comments.

8 Comments

Thank you so much... Will not I be your friends on facebook?? I am waiting , Facebook
Hey I need to determine that roll 5 rows is open. But how??
I'm little bit busy, I'll back soon.
@SabbirTT, what do you mean by "I need to determine that roll 5 rows is open."?
If you want to get only roll no 5, then use Top 1 in sql. SQL: SELECT Top 1 roll FROM cmt_7th WHERE name IS Null And department IS Null And phone IS Null.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.