SQL中首先建立一个结构一样的自定义类型的表格,在存储空间中申明一个此类型的变量,此处注意此时后面必须有readonly,如:
@paravalue_insert MaterialStruct readonly,//此处注意此时后面必须有readonly,否则会报错,http://www.mamicode.com/info-detail-1485151.html
当传入多个参数时,可以用Dictionary<string, object>,把参数都包含其中,如:
parmWithValue = new Dictionary<string, object>()//http://www.cnblogs.com/txw1958/archive/2012/11/07/csharp-dictionary.html { {"paravalue_delete" ,datadelete_origin}, {"paravalue_update" ,dataupdate}, {"@paravalue_insert" ,datainsert}, }; foreach (var v in parmWithValue) { cmd.Parameters.AddWithValue(v.Key, v.Value);//http://blog.csdn.net/highplayer/article/details/6560167 } SqlDataAdapter sqlDa = new SqlDataAdapter(cmd); resultDs = new DataSet(); sqlDa.Fill(resultDs);
设置好参数后,在传入时遍历每一个参数,其余与其他类型参数传入一模一样。