通过多表的内置SQL在GridView上显示数据

时间:2019-04-16 03:34:34

标签: c# asp.net

GridView1不显示SQL语句带来的数据 为:

... {用于选择放置SQL语句的属性和条件的语句} (关于SQL的示例:SELECT [患者] .name_ Patient来自患者,visitFACTABLE,日期时间,疾病,其中[患者] .Id_ Patient = [visitFACTABLE] .Id AND [visitFACTABLE] .Id = [datetime] .Id_datetime AND [Patient] .gender_ Patient = “男”)

    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
    con.Open();
    string q_sql = "SELECT " + slct + " FROM patient, visitFACTABLE, datetime, disease WHERE [patient].Id_patient = [visitFACTABLE].Id AND [visitFACTABLE].Id = [datetime].Id_datetime " + w;SqlDataAdapter da = new SqlDataAdapter(q_sql, con);
    DataTable dt = new DataTable();
    da.Fill(dt);
    GridView1.DataSource = dt;
    GridView1.DataBind();

1 个答案:

答案 0 :(得分:0)

触发调试器断点@ GridView1.DataSource = dt;

enter image description here

然后将鼠标悬停并可视化并检查您的dt(数据表)是否至少包含1行。如果有row,那么您的Gridview应该会显示数据