StringBuilder strSql=new StringBuilder();
strSql.Append("insert into HT_XunJiaMain(");
strSql.Append("b_xunjiazhuti,b_xunjiariqi,b_lianxiren,b_lianxidianhua,b_dizhi)");
strSql.Append(" values (");
strSql.Append("@b_xunjiazhuti,@b_xunjiariqi,@b_lianxiren,@b_lianxidianhua,@b_dizhi)");
strSql.Append(";set @ReturnValue= @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@b_xunjiazhuti", SqlDbType.VarChar,),
new SqlParameter("@b_xunjiariqi", SqlDbType.VarChar,),
new SqlParameter("@b_lianxiren", SqlDbType.VarChar,),
new SqlParameter("@b_lianxidianhua", SqlDbType.VarChar,),
new SqlParameter("@b_dizhi", SqlDbType.VarChar,),
new SqlParameter("@ReturnValue",SqlDbType.Int)};
parameters[].Value = model.b_xunjiazhuti;
parameters[].Value = model.b_xunjiariqi;
parameters[].Value = model.b_lianxiren;
parameters[].Value = model.b_lianxidianhua;
parameters[].Value = model.b_dizhi;
parameters[].Direction = ParameterDirection.Output; //这里输出的主表的ID List<CommandInfo> sqllist = new List<CommandInfo>();
CommandInfo cmd = new CommandInfo(strSql.ToString(), parameters);
sqllist.Add(cmd);
StringBuilder strSql2;
foreach (HT_Model.HT_XunJiaDetails models in model.HT_XunJiaDetailss)
{
strSql2=new StringBuilder();
strSql2.Append("insert into HT_XunJiaDetails(");
strSql2.Append("d_baojialeixing,d_baojiayuan,d_beizhu,Pid,d_laiyuan,d_bianhao,d_zuzhiguige,d_buzhong,d_kezhong,d_baojiariqi,d_jiage)");
strSql2.Append(" values (");
strSql2.Append("@d_baojialeixing,@d_baojiayuan,@d_beizhu,@Pid,@d_laiyuan,@d_bianhao,@d_zuzhiguige,@d_buzhong,@d_kezhong,@d_baojiariqi,@d_jiage)");
SqlParameter[] parameters2 = {
new SqlParameter("@d_baojialeixing", SqlDbType.VarChar,),
new SqlParameter("@d_baojiayuan", SqlDbType.VarChar,),
new SqlParameter("@d_beizhu", SqlDbType.VarChar,),
new SqlParameter("@Pid", SqlDbType.Int,),
new SqlParameter("@d_laiyuan", SqlDbType.VarChar,),
new SqlParameter("@d_bianhao", SqlDbType.VarChar,),
new SqlParameter("@d_zuzhiguige", SqlDbType.VarChar,),
new SqlParameter("@d_buzhong", SqlDbType.VarChar,),
new SqlParameter("@d_kezhong", SqlDbType.VarChar,),
new SqlParameter("@d_baojiariqi", SqlDbType.VarChar,),
new SqlParameter("@d_jiage", SqlDbType.VarChar,)};
parameters2[].Value = models.d_baojialeixing;
parameters2[].Value = models.d_baojiayuan;
parameters2[].Value = models.d_beizhu;
parameters2[].Direction = ParameterDirection.InputOutput;
//这里将主表的ID作为参数传入子表ParentID,这要是这这里的写法
//parameters2[3].Direction = ParameterDirection.InputOutput;
//这样对应到后面的数据库处理就好了,代码自动生成的时候,这里不能自动转换,需要手动修改
parameters2[].Value = models.d_laiyuan;
parameters2[].Value = models.d_bianhao;
parameters2[].Value = models.d_zuzhiguige;
parameters2[].Value = models.d_buzhong;
parameters2[].Value = models.d_kezhong;
parameters2[].Value = models.d_baojiariqi;
parameters2[].Value = models.d_jiage; cmd = new CommandInfo(strSql2.ToString(), parameters2);
sqllist.Add(cmd);
}
DbHelperSQL.ExecuteSqlTranWithIndentity(sqllist);
return (int)parameters[].Value;
05-11 14:48