Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C sql如何将特定列的数据获取到datagrid_C#_Sql_Wpf_Datagrid - Fatal编程技术网

C# C sql如何将特定列的数据获取到datagrid

C# C sql如何将特定列的数据获取到datagrid,c#,sql,wpf,datagrid,C#,Sql,Wpf,Datagrid,我想在我的C WPF数据网格上显示特定的列 我使用此代码获取所选列: 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("cm

我想在我的C WPF数据网格上显示特定的列

我使用此代码获取所选列:

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;
}
但我只想显示列数据为空的行

左边的图像是输出屏幕短,右边的图像是sql表图像,就像这个链接图像一样


我想得到第5到第10行,忽略所有列都不为空的第1到第4行。

根据您的描述,您想得到姓名、部门、电话都为空的所有行。因此,您必须在sql中应用条件。请检查以下内容:

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;

}
检查SQL的以下输出:


非常感谢你。。。我会成为你在facebook上的朋友吗??我在等,嘿,我需要确定第5行是否打开。但是怎么办?我有点忙,我很快就会回来。@SabbirTT,你说我需要确定第5卷行是否打开是什么意思。?如果你只想得到第5卷,那么使用sql中的前1。SQL:从cmt_第七卷中选择前1卷,其中名称为空,部门为空,电话为空。