判断DataReader是不是为空!
代码
string connString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
connString += Server.MapPath("~/jinhai.mdb");
OleDbConnection conn = new OleDbConnection(connString);
string seStr = "select * from kehu where user_name like @user_name";
OleDbCommand comm = new OleDbCommand(seStr, conn);
string name = "%" + txtName1.Text.ToString().Trim() + "%";
comm.Parameters.AddWithValue("@user_name", name);
conn.Open();
OleDbDataReader dr = comm.ExecuteReader();
if (dr.HasRows)
{
myReapeter.DataSource = dr;
myReapeter.DataBind();
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "afsdgfdh", "alert('没有此客户的任何记录!');", true);
}
dr.Close();
conn.Close();
connString += Server.MapPath("~/jinhai.mdb");
OleDbConnection conn = new OleDbConnection(connString);
string seStr = "select * from kehu where user_name like @user_name";
OleDbCommand comm = new OleDbCommand(seStr, conn);
string name = "%" + txtName1.Text.ToString().Trim() + "%";
comm.Parameters.AddWithValue("@user_name", name);
conn.Open();
OleDbDataReader dr = comm.ExecuteReader();
if (dr.HasRows)
{
myReapeter.DataSource = dr;
myReapeter.DataBind();
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "afsdgfdh", "alert('没有此客户的任何记录!');", true);
}
dr.Close();
conn.Close();