联系我们

为客户提供超预期的高品质网站设计!

sql参数化入库

2017-12-25 0:00:00

===inset into===


SqlConnection conn = sqlHelper.CreateDB();
cmdStr = "insert into weiZhangCityFromBaiJie (name,prefix,vin,engine,model) values (@name,@prefix,@vin,@engine,@model)";
SqlCommand com = new SqlCommand(cmdStr, conn);
com.Parameters.Clear();
com.Parameters.Add("@sourceID", 555);
com.Parameters.Add("@name", "maolian.net");
....

conn.Open();
com.ExecuteNonQuery();
conn.Close();



===inset into返回插入后的ID===

SqlConnection conn = sqlhelper.CreateDB();
SqlCommand com = conn.CreateCommand();
com.CommandText = "insert into cheLiangXinXi (name,lianXiRen) values (@chePaiHaoMa,'订单客户') SELECT @@IDENTITY as ID";
com.Parameters.Clear();
com.Parameters.Add("@chePaiHaoMa", chePai);
chePaiID= com.ExecuteScalar().ToString();





===updaet===

conn = dbHelper.CreateDB();
        com = conn.CreateCommand();
        com.CommandText = "update users set yaoWeiShuXingID=@yaoWeiShuXing,shenGaoShuXingID=@shenGaoShuXing,yaoWei=@yaoWei,shenGao=@shenGao where ID=@ID";
        com.Parameters.Clear();
        com.Parameters.Add("@yaoWeiShuXing", this.Ddl_yaoWei.SelectedValue);
        com.Parameters.Add("@shenGaoShuXing", this.Ddl_shenGao.SelectedValue);
        com.Parameters.Add("@yaoWei",Text.killURLattack (this.Tb_yaoWei.Text));
        com.Parameters.Add("@shenGao", Text.killURLattack(this.Tb_shenGao.Text));
        com.Parameters.Add("@ID", Session["S_userID"]);
        conn.Open();
        com.ExecuteNonQuery();
        conn.Close();


===inset into===

SqlConnection conn = dbhelper.CreateDB();
        SqlCommand com = conn.CreateCommand();
        StringBuilder sb = new StringBuilder();

com.CommandText = "select * from yeWu where yanCheDianID=@yanCheDianID and datediff(day,yueYanRiQi,@riQi)=0 ";
        com.Parameters.Clear();
        com.Parameters.Add("@yanCheDianID", yanCheDianID);
        com.Parameters.Add("@riQi", riQi);

        adapt = new SqlDataAdapter(com);
        adapt.Fill(ds);
        dt = ds.Tables[0];
        if (dt.Rows.Count > 0){

foreach (DataRow dr in dt.Rows)

{

}

}

上一条新闻:JS邮箱验证-正则验证
下一条新闻:asp.net 动态添加Meta 属性

 

400-6137-308 54057491 info@maolian.net