string path=Server.MapPath("book.xls");
string strconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+path+";Extended Propertie*=**cel 8.0";
string sql= "select * from [book$] where num = "+ka;
//string getv=null;
//string name=null;
OleDbConnection conn = new OleDbConnection(strconn);
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql,conn);
OleDbDataReader dr=cmd.ExecuteReader(CommandBehavior.CloseConnection);
try
{
if(dr.Read())
{
string name=dr.GetValue(1).ToString();
string getv=dr.GetValue(2).ToString();
//name=dr.
dr.Close();
Response.Redirect("search.aspx?jifen="+getv+"&ka="+ka+"&name="+name);
// Response.Write(dr.GetValue(3)+"<br>");
// Response.Write(dr.GetName(0).ToString()+"<br>");
}
else
{
Response.Write(PublicRule.AlertScript("你查找的数据不存在!",1));
Response.End();
}
}
finally
{
dr.Close();
conn.Close();
}
表名 要为英文,数据的第一行如果为空!下面的将全部默认为字符串,如果第一个为数字,那么字符串将默认为0
string strconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+path+";Extended Propertie*=**cel 8.0";
string sql= "select * from [book$] where num = "+ka;
//string getv=null;
//string name=null;
OleDbConnection conn = new OleDbConnection(strconn);
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql,conn);
OleDbDataReader dr=cmd.ExecuteReader(CommandBehavior.CloseConnection);
try
{
if(dr.Read())
{
string name=dr.GetValue(1).ToString();
string getv=dr.GetValue(2).ToString();
//name=dr.
dr.Close();
Response.Redirect("search.aspx?jifen="+getv+"&ka="+ka+"&name="+name);
// Response.Write(dr.GetValue(3)+"<br>");
// Response.Write(dr.GetName(0).ToString()+"<br>");
}
else
{
Response.Write(PublicRule.AlertScript("你查找的数据不存在!",1));
Response.End();
}
}
finally
{
dr.Close();
conn.Close();
}
表名 要为英文,数据的第一行如果为空!下面的将全部默认为字符串,如果第一个为数字,那么字符串将默认为0