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


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

    天道酬勤,厚积薄发。 君子之行,静以修身,俭以养德。 非淡泊无以明志,非宁静无以致远。 如有恒,何须三更起,半夜眠;最怕莫,三天打鱼两天晒网,竹篮打水一场空。
  • 相关阅读:
    (unix domain socket)使用udp发送>=128K的消息会报ENOBUFS的错误
    HTTP KeepAlive模式
    Windows 7 中的 God Mode
    我的开发环境配置经验
    C#格式化数值结果表(格式化字符串)
    我可怜的笔记本电脑
    JetBrains ReSharper 5.x 注册机
    异常处理准则
    调用 Windows 7 中英文混合朗读
    oracle笔记(2010130)
  • 原文地址:https://www.cnblogs.com/houweidong/p/12285847.html
Copyright © 2020-2023  润新知