public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// 更新确认数据
/// </summary>
private void gxdata()
{
int res;
string c1 = "确认收到";
string dw = this.DropDownList1.SelectedValue;
string commstr = @"update data set c1='" + c1 + "'" + @"where dw='" + dw + "'";
//"insert into data(c1) values('" + c1 + "')"
OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=|datadirectory|data.mdb;");
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
OleDbCommand cmd = new OleDbCommand(commstr, conn);
try
{
res = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new Exception("error", ex);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
if (res > 0)
{
Response.Write("确认收到,谢谢支持!");
}
else
{
Response.Write("确认失败");
}
}
/// <summary>
/// 显示数据库中所有内容
/// </summary>
private void binddata()
{
string commstr = @"select dw,c1 from data";
DataTable dt = new DataTable();
OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=|datadirectory|data.mdb;");
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
OleDbCommand comm = new OleDbCommand(commstr, conn);
using (OleDbDataReader sdr = comm.ExecuteReader(CommandBehavior.CloseConnection))
{
dt.Load(sdr);
}
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
/// <summary>
/// 输出数据库
/// </summary>
/// <param name="dw"></param>
/// <param name="pass"></param>
/// <returns></returns>
private static DataTable outdata(string dw, string pass)
{
string commstr = @"select * from pass where dw='" + dw + "'" + @"and pass='" + pass + "'";
DataTable dt = new DataTable();
OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=|datadirectory|data.mdb;");
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
OleDbCommand comm = new OleDbCommand(commstr, conn);
using (OleDbDataReader sdr = comm.ExecuteReader(CommandBehavior.CloseConnection))
{
dt.Load(sdr);
}
return dt;
}
/// <summary>
/// 调用数据输出,调用更新数据库
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button2_Click(object sender, EventArgs e)
{
if (this.DropDownList1.SelectedIndex > 0)
{
string dw = this.DropDownList1.SelectedValue;
string pass = this.TextBox1.Text.ToString();
DataTable dt = outdata(dw, pass);
if (dt.Rows.Count > 0)
{
Response.Write("确认码正确!");
gxdata();
}
else
{
Response.Write("确认码不正确");
}
}
else
{
Response.Write("请选择单位!");
return;
}
}
/// <summary>
/// 查看数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
binddata();
}
}