C#ASP.NET怎么使用count函数,然后将计算结果用GridView显示出来 10
SqlConnectionconn=newSqlConnection(strCon);conn.Open();stringsql="selectcount(学号)as人数...
SqlConnection conn = new SqlConnection(strCon);
conn.Open();
string sql = "select count(学号)as人数 from 学生表"
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
checkview.DataSource = ds.Tables[0].DefaultView;
checkview.DataBind();
cmd.Dispose();
conn.Close();
conn.Dispose();
这是我的程序,为什么GridView不显示呢 展开
conn.Open();
string sql = "select count(学号)as人数 from 学生表"
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
checkview.DataSource = ds.Tables[0].DefaultView;
checkview.DataBind();
cmd.Dispose();
conn.Close();
conn.Dispose();
这是我的程序,为什么GridView不显示呢 展开
2个回答
展开全部
把sql语句写进SqlDataSource里,下面给VB.net的例子
触发button的点击事件,执行如下代码
Dim sql As String
sql = "select * from tableA where id >''"
If Not textbox1.text.trim = "" Then
sql = sql & " and colB = '" & textbox1.Text.trim & "'"
End If
sql = sql & " order by id desc"
SqlDataSource7.SelectCommand = sql
GridView1.DataSourceID = "SqlDataSource7"
GridView1.DataBind()
触发button的点击事件,执行如下代码
Dim sql As String
sql = "select * from tableA where id >''"
If Not textbox1.text.trim = "" Then
sql = sql & " and colB = '" & textbox1.Text.trim & "'"
End If
sql = sql & " order by id desc"
SqlDataSource7.SelectCommand = sql
GridView1.DataSourceID = "SqlDataSource7"
GridView1.DataBind()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询