C# 访问数据库

select:

string m_sfzh = TxtBoxSfz.Text.ToString();
        string constr = ConfigurationManager.ConnectionStrings["NcreUtilsConnectionString"].ConnectionString;
        SqlConnection con = new SqlConnection(constr);
        if (con.State != ConnectionState.Open)
        {
            con.Open();
        }
        SqlCommand datacommand1 = new SqlCommand("select * from T_Zkzxx where SFZH = '" + m_sfzh + "'", con);
        //string sqlstr = "select * from T_Zkzxx where SFZH = '" + m_sfzh + "'";
        //string sqlstr = "select * from T_Zkzxx";
        //SqlCommand datacommand1 = new SqlCommand();
        //datacommand1.Connection = con;

        //datacommand1.CommandText = sqlstr;

        DataTable dt1 = new DataTable();
        dt1.Load(datacommand1.ExecuteReader());
        GridViewYzkzh.DataSource = dt1;
        GridViewYzkzh.DataBind();
        con.Close();

insert:

string Lsh = TxtBox_Lsh.Text.ToString();
        string Sfzh = TxtBox_SFZH.Text.ToString();
        int Xgxxzl = DrpLst_Xxzl.SelectedIndex;
        string Yxx = TxtBox_Yxx.Text.ToString();
        string Xgxx = TxtBox_Xgxx.Text.ToString();
        string constr = ConfigurationManager.ConnectionStrings["NcreUtilsConnectionString"].ConnectionString;
        //SqlConnection con = new SqlConnection("Data Source=SWJTU-EB81DB430\\SWJTUCJY;Initial Catalog=xiaokaocj;Integrated Security=True");
        SqlConnection con = new SqlConnection(constr);
        con.Open();
        SqlCommand cmd = new SqlCommand("insert into T_Bmxxxg values('"+Lsh+"','"+Sfzh+"',"+Xgxxzl+",'"+Yxx+"','"+Xgxx+"',getdate())", con);
        cmd.ExecuteNonQuery();
        con.Close();
        foreach (object obj in yourformID.Controls)
        {
            if (obj is TextBox)
            {
                TextBox tb = (TextBox)obj;
                tb.Text = "";
            }

        }
        Response.Write("<script>alert('信息修改成功');</script>;");
        //Response.Redirect("Bmxxxg.aspx");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值