SqlParameter数组添加到SqlCommand中,CommandType.Text

   protected void Button1_Click(object sender, EventArgs e)
    {
        string strSql="insert into Invoice_Rebate_Customer_L (FORM_ID,LINE_NO) values (@formNo,@lineNo)";       
        SqlParameter[] paras =new SqlParameter[2];
        paras[0] = new SqlParameter("@formNo", SqlDbType.NVarChar);
        paras[0].Value = "88888";
        paras[1] = new SqlParameter("@lineNo", SqlDbType.Int);
        paras[1].Value = 8;
        ExecuteSql(strSql, paras, CommandType.Text);   
    }
    void ExecuteSql(string strSql,SqlParameter[] paras,CommandType cmdType)
    {
        SqlConnection con = new SqlConnection("Server=aukm2;Database=BU;UID=buuser;PWD=buinfo");
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = cmdType;
        cmd.CommandText = strSql;       
        foreach (SqlParameter p in paras)
        {
            cmd.Parameters.Add(p);
        }
        cmd.ExecuteNonQuery();
        con.Close();
    }
posted @ 2009-06-03 15:15  只想做好  阅读(3569)  评论(1编辑  收藏  举报