using System;
using System.Collections.Generic;
using System.Text;
using IDAL;
using System.Data.SqlClient;
using System.Data;
using Model;
using System.Configuration;
using System.Web;
using System.Xml;
using System.Xml.Schema;using DBUtility;namespace SQLServerDal
{
    public class SurveyDal : ISurvey
    {        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Survey survey)
        {            //string cmdText = "insert into Survey (Address,Jiekuan,Work,Workplace,position,LoanBalance,LoanTerm,LoanWay,LoanKind,LoanUses,RepaymentDay,RepaymentWay,Contact,BasicInfo,OtherInfo,FinanceInfo) values(@Address,@Jiekuan,@Work,@Workplace,@position,@LoanBalance,@LoanTerm,@LoanWay,@LoanKind,@LoanUses,@RepaymentDay,@RepaymentWay,@Contact,@BasicInfo,@OtherInfo,@FinanceInfo )";
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Survey(Address) values (@Address)");
            strSql.Append("Address");
            strSql.Append(" values (");
            strSql.Append("@Address)");
            strSql.Append(";select @@IDENTITY");
            
            SqlParameter[] param = 
                //new SqlParameter[] 
                                  {
                                      new SqlParameter("@Address",SqlDbType.NVarChar,100),
                                    new SqlParameter("@Work",SqlDbType.NVarChar,100),
                                 //new SqlParameter("@Workplace",SqlDbType.NVarChar,100),
                                 //new SqlParameter("@Position",SqlDbType.NVarChar,100),
                                 //new SqlParameter("@LoanBlalance",SqlDbType.NVarChar,100),
                                 //new SqlParameter("@LoanTerm",SqlDbType.NVarChar,100),
                                 //new SqlParameter("@LoanWay",SqlDbType.NVarChar,100),
                                 //new SqlParameter("@LoanKind",SqlDbType.NVarChar,100),
                                 //new SqlParameter("@LoanUses",SqlDbType.NVarChar,100),
                                 //new SqlParameter("@RepaymentDay",SqlDbType.NVarChar,100),
                                 //new SqlParameter("@RepaymentWay",SqlDbType.NVarChar,100),
                                 //new SqlParameter("@Contact",SqlDbType.NVarChar,100),
                                 //new SqlParameter("@BasicInfo",SqlDbType.NVarChar,100),
                                 //new SqlParameter("@OtherInfo",SqlDbType.NVarChar,100),
                                 //new SqlParameter("@FinanceInfo",SqlDbType.NVarChar,100)
         
                                    };
                             
            param[0].Value = survey.Address;
            //param[1].Value = survey.Jiekuan;
            param[2].Value = survey.Work;
       //     param[3].Value = survey.Workplace;
       //     param[4].Value = survey.position;
       //     param[5].Value = survey.LoanBalance;
       //     param[6].Value = survey.LoanTerm;
       //     param[7].Value = survey.LoanWay;
       //     param[8].Value = survey.LoanKind;
       //     param[9].Value = survey.LoanUses;
       //     param[10].Value = survey.RepaymentDay;
       //     param[11].Value = survey.RepaymentWay;
       //     param[12].Value = survey.Contact;
       //     param[13].Value = survey.BasicInfo;
       //     param[14].Value = survey.OtherInfo;
       //param[15].Value=survey.FinanceInfo;       //SQLHelper sqlhelper = new SQLHelper();
            object obj = SQLHelper.ExecuteNonQuery(SQLHelper.connString, CommandType.Text, strSql.ToString(), param);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
           
            



  
    //Opinion text, ----审核意见
    //opinionDay datetime   ----审核日期
        }        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel(string loanNum)
        {
            
        }    }
}现在不能插入 
刚刚可以插入 
但是不论我怎么改 都是只能插入 address
好神奇呀
大家帮我看看那里出错了  麻烦各位了 

解决方案 »

  1.   

    [Quote=引用 1 楼 randomfeel 的回复:]
    太长了。。看不清
    [/Quot]
      

  2.   

    using System; 
    using System.Collections.Generic; 
    using System.Text; 
    using IDAL; 
    using System.Data.SqlClient; 
    using System.Data; 
    using Model; 
    using System.Configuration; 
    using System.Web; 
    using System.Xml; 
    using System.Xml.Schema; using DBUtility; namespace SQLServerDal 

        public class SurveyDal : ISurvey 
        {         /// <summary> 
            /// 增加一条数据 
            /// </summary> 
            public int Add(Survey survey) 
            {                        StringBuilder strSql = new StringBuilder(); 
                strSql.Append("insert into Survey(Address) values (@Address)"); 
                strSql.Append("Address"); 
                strSql.Append(" values ("); 
                strSql.Append("@Address)"); 
                strSql.Append(";select @@IDENTITY"); 
                
                SqlParameter[] param = 
                    //new SqlParameter[] 
                                      { 
                                          new SqlParameter("@Address",SqlDbType.NVarChar,100), 
                                        new SqlParameter("@Work",SqlDbType.NVarChar,100), 
                                  
                                        }; 
                                
                param[0].Value = survey.Address; 
                        param[2].Value = survey.Work; 
        
                object obj = SQLHelper.ExecuteNonQuery(SQLHelper.connString, CommandType.Text, strSql.ToString(), param); 
                if (obj == null) 
                { 
                    return 0; 
                } 
                else 
                { 
                    return Convert.ToInt32(obj); 
                }         }         /// <summary> 
            /// 得到一个对象实体 
            /// </summary> 
            
      

  3.   

    参数不对吧,怎么是param[0]和param[2]
      

  4.   

      param[0].Value = survey.Address; 
                //param[1].Value = survey.Jiekuan; 
                param[2].Value = survey.Work; 
      

  5.   

    sql语句里只插入了@Address一个参数
      

  6.   

         StringBuilder strSql = new StringBuilder(); 
                strSql.Append("insert into Survey(Address) values (@Address)"); 
                strSql.Append("Address"); 
                strSql.Append(" values ("); 
                strSql.Append("@Address)"); 
                strSql.Append(";select @@IDENTITY"); 红色标明的地方