17,748
社区成员




protected void Page_Load(object sender, EventArgs e)
{
string sql = "select pretime from preInfo where stuNum='" + textBox1.Text + "' ";
Response.Write(ReturnDataTable(sql).Rows[0][0].ToString());
}
public static DataTable ReturnDataTable(string cmdtext)
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "数据库连接字符串";
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd = new SqlCommand(cmdtext, cn);
cmd.CommandType = CommandType.Text; ;
SqlDataReader dr = null;
using (dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
dt.Load(dr);
}
return dt;
}