DataTable dtLys = lyp.GetZuHuoShiSJ(dtLy ,sess .LYDlZsDel,sj);
gvLyInfo.DataSource = dtLys;
gvLyInfo.DataBind();string ss = string.Format("dtLys.rows.count={0}", dtLys.Rows.Count);
messbox(ss );
上面的程序段在检测时确实指出dtLys.Rows.Count有若干条记录,但GridView确说没有可显示的数据。请高手指点出错的原因。十分感谢!
gvLyInfo.DataSource = dtLys;
gvLyInfo.DataBind();string ss = string.Format("dtLys.rows.count={0}", dtLys.Rows.Count);
messbox(ss );
上面的程序段在检测时确实指出dtLys.Rows.Count有若干条记录,但GridView确说没有可显示的数据。请高手指点出错的原因。十分感谢!
{
public const string connectionString = "Data Source=.;Initial Catalog=BirthdayRemind;Integrated Security=True"; /// <summary>
/// 根据条件返回书籍信息
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public static DataTable GetData(string sql)
{
DataTable dt = null;
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlDataAdapter sda=new SqlDataAdapter(sql,conn);
DataSet ds=new DataSet();
sda.Fill(ds); if (ds.Tables.Count > 0)
dt = ds.Tables[0];
} return dt;
}
} private void btn_Search_Click(object sender, EventArgs e)
{
string sql = GetCondition();
DataTable dt=PubData.GetData(sql); //显示书籍信息
dataGridView1.DataSource = dt;//这样就行了,顺便可以设置列的数据源绑定咧名称
} /// <summary>
/// 拼接条件
/// </summary>
/// <returns></returns>
private string GetCondition()
{
StringBuilder sb = new StringBuilder();
sb.Append("select *From BookInfo where");
sb.Append(" BookName like '%"+txt_BookName.Text.Trim()+"%'");
sb.Append(" and Author like '%"+txt_Author.Text.Trim()+"%'");
sb.Append(" and Press like '%"+txt_Press.Text.Trim()+"%'"); return sb.ToString();
}
参考http://www.cnblogs.com/huangjianhuakarl/archive/2009/02/03/1381710.html
DataTable dtLys = lyp.GetZuHuoShiSJ(dtLy ,sess .LYDlZsDel,sj);
gvLyInfo.DataSource = dtLys.DefaulView;
gvLyInfo.DataBind();
string ss = string.Format("dtLys.rows.count={0}", dtLys.Rows.Count);
你试一下
{}