sqlexec进程收到的语句ID无效

时间:2013-03-11 09:25:18

标签: c# asp.net performance connection informix

我在插入过程中面临以下问题(多行):(插入了一些记录,在随机数量的记录后出现错误)!!

  

sqlexec进程收到的无效语句ID。


  public static int InsertGroupDetails(List<GroupDetails> grp_det)
        {

            using (IfxConnection con = new IfxConnection(ConfigurationSettings.AppSettings["str_rm"].ToString()))
            {
                int affectedRow = -1;
                StringBuilder cmdTxt = new StringBuilder();
                cmdTxt.Append(" INSERT INTO rdm_groupdetails(group_id,dep_code,dep_year,dep_name,boss_num,boss_name) VALUES (?, ?, ?, ?, ?, ? ) ");
                foreach (GroupDetails grp in grp_det)
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }


                    IfxCommand myIfxCmd = new IfxCommand(cmdTxt.ToString(), con);

                    myIfxCmd.CommandType = CommandType.Text;
                    myIfxCmd.Parameters.Clear();

                    myIfxCmd.Parameters.Add("group_id", grp.Group_id);
                    myIfxCmd.Parameters.Add("dep_code", grp.Dep_code);
                    myIfxCmd.Parameters.Add("dep_year", grp.Dep_year);
                    myIfxCmd.Parameters.Add("dep_name", grp.Dep_name);
                    myIfxCmd.Parameters.Add("boss_num", grp.Boss_code);
                    myIfxCmd.Parameters.Add("boss_name", grp.Boss_name);

                    affectedRow = myIfxCmd.ExecuteNonQuery();


                }
                con.Close();
                con.Dispose();
                return affectedRow;
            }

        }

1 个答案:

答案 0 :(得分:2)

最有可能的是grp.Group_idgrp.Dep_codegrp.Dep_yeargrp.Dep_namegrp.Boss_codegrp.Boss_name中的一个{{1}至少有一个null。不发送grp的参数值;你可能会重写:

null

等(即每个人);对于任何此类值,这将传递数据库myIfxCmd.Parameters.Add("group_id", ((object)grp.Group_id) ?? DBNull.Value); (与C#null不同)。

我要做的第二件事是重用一个命令实例:

null