用一个DATALIST绑定了一个数据,然后写了一个类,想查询所需要的记录,但是查询的结果只显示DATALIST的HEAD,不显示绑定的数据,请高手指教,谢谢
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AFATConnectionString"].ConnectionString);
private SqlCommand comm;
private SqlDataReader sqldr; public bool select(string a)
{
comm = new SqlCommand("select * from bottle where tagID='"+a+"'", conn);
sqldr = null;
conn.Open();
sqldr = comm.ExecuteReader();
if (sqldr.Read())
{
DataList1.DataSource = sqldr;
DataList1.DataKeyField = "tagID";
DataList1.DataBind();
sqldr.Close();
return true;
}
else { return false; }
}
protected void Button1_Click(object sender, EventArgs e)
{ if (select(TextBox1.Text.Trim()) == true)
{
DataList1.Visible = true;
}
else
{
Response.Write("<script language=javascript>alert('没有您要找的记录')</script>");
}
}
}
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AFATConnectionString"].ConnectionString);
private SqlCommand comm;
private SqlDataReader sqldr; public bool select(string a)
{
comm = new SqlCommand("select * from bottle where tagID='"+a+"'", conn);
sqldr = null;
conn.Open();
sqldr = comm.ExecuteReader();
if (sqldr.Read())
{
DataList1.DataSource = sqldr;
DataList1.DataKeyField = "tagID";
DataList1.DataBind();
sqldr.Close();
return true;
}
else { return false; }
}
protected void Button1_Click(object sender, EventArgs e)
{ if (select(TextBox1.Text.Trim()) == true)
{
DataList1.Visible = true;
}
else
{
Response.Write("<script language=javascript>alert('没有您要找的记录')</script>");
}
}
}
你先到数据库中查下,是否有记录
ddlType.DataTextField="RetiretypeName";
ddlType.DataValueField="RetiretypeNO";
ddlType.DataBind();
其中dsType是dataset,你最好也把它的DataValueField字段也绑定,懂得知识的活用,理解了原理,自然能够以不变应万变。
{
comm = new SqlCommand("select * from bottle where tagID='"+a+"'", conn);
sqldr = null;
conn.Open();
sqldr = comm.ExecuteReader(); DataList1.DataSource = sqldr;
DataList1.DataKeyField = "tagID";
DataList1.DataBind();
if (DataList1.Items.Count > 0)
return true;
return false
}
{
DataList1.DataSource = sqldr;
DataList1.DataKeyField = "tagID";
DataList1.DataBind();
sqldr.Close();
return true;
}
else { return false; }
>>>>
DataList1.DataSource = sqldr;
DataList1.DataKeyField = "tagID";
DataList1.DataBind();
sqldr.Close();
return sqldr.HasRows;
{
comm = new SqlCommand("select * from bottle where tagID='"+a+"'", conn);
sqldr = null;
conn.Open();
sqldr = comm.ExecuteReader();
if (sqldr.Read())
{
DataList1.DataSource = sqldr;
DataList1.DataKeyField = "tagID";
DataList1.DataBind();
sqldr.Close();
return true;
}
else { return false; }
}
{
comm = new SqlCommand("select * from bottle where tagID='"+a+"'", conn);
sqldr = null;
conn.Open();
sqldr = comm.ExecuteReader();
if (sqldr.Read())
{
DataList1.DataSource = sqldr;
DataList1.DataKeyField = "tagID";
DataList1.DataBind();
sqldr.Close();
return true;
}
else { return false; }
}
sqldr = comm.ExecuteReader();
if (sqldr.Read())
{
DataList1.DataSource = sqldr;
DataList1.DataKeyField = "tagID";
DataList1.DataBind();
sqldr.Close();
return true;
}