确认收到信息,asp.net c#

2021-01-13 23:11

阅读:474

标签:def   bind   count   comm   event   str   load   opd   idv   

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

///


/// 更新确认数据
///

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("确认失败");
}
}

///


/// 显示数据库中所有内容
///

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();
}


///


/// 输出数据库
///

///
///
///
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;
}

 

///


/// 调用数据输出,调用更新数据库
///

///
///
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;
}

}

///


/// 查看数据
///

///
///
protected void Button1_Click(object sender, EventArgs e)
{
binddata();
}
}

确认收到信息,asp.net c#

标签:def   bind   count   comm   event   str   load   opd   idv   

原文地址:https://www.cnblogs.com/houweidong/p/12285847.html


评论


亲,登录后才可以留言!