看看表的数据有什么特殊的,比如null,等等

解决方案 »

  1.   

    好吧,我重贴
    public void DataCoherent1()
    { //--1
    //string aa=null;
    string strCol=null;//存列的名
    string strColValue=null;//存列的alues值
    string sKeyName=null;//存主键的字段名
    string sKNValue=null;//存主键的values
    strDSN=LinkSqlData();
    sAccDsn=LinkAccData();
    //DataTable AccDT = new DataTable();
    string[] sFldNam;
    int iFldCount;
    int iRcdCnt;
    int iTbl=Convert.ToInt32(GetTblCount());//取得表个数
    for(int i=0;i<iTbl;i++)
       {//--2

             string sTblName=GetTblName(i);//取得表的名称
    iRcdCnt=GetRecordCount(sTblName);//取得表里记录的个数;
    OleDbConnection AccConn=new OleDbConnection(sAccDsn);  string strAccSQL = "Select * from "+sTblName+" order by Utime_bak";
    OleDbDataAdapter AccDA= new OleDbDataAdapter(strAccSQL,AccConn); 
    AccDA.Fill(AccDT); iFldCount=Convert.ToInt32(GetFldNameCount(sTblName));//取得字段个数
    sFldNam=new string[iFldCount+3];
    for(int iR=0;iR<iRcdCnt;iR++)//记录里的循环
    {//--3
    strCol=null;
    strColValue=null;

    for(int j=0;j<iFldCount;j++)//记录的列的循环
    {//--4
               sFldNam[j]=GetFldName(sTblName,j);
              //取得字段名sql的。access多三个state_bak,Utime_bak,CurUserName_bak
    if(j==iFldCount-1)
    {//--5
    strCol+=sFldNam[j].ToString();
    strColValue+=
                                "'"+AccDT.Rows[iR][sFldNam[j].ToString()]+"'";
    }//--5
    else 
    {//--6
    strCol+=sFldNam[j]+",";//取得列名的串
    strColValue+=
                              "'"+AccDT.Rows[iR][sFldNam[j].ToString()]
                              .ToString()+"'"+",";
                              //取得列的values的值
    }//--6
    // aa=sFldNam[j];
    }//-4
    sFldNam[iFldCount]="state_bak";
    sFldNam[iFldCount+1]="Utime_bak";
    sFldNam[iFldCount+2]="CurUserName_bak";
    sKeyName=GetKeyName(sTblName).Trim();
                               //取得当前表的主键名---
    sKNValue=AccDT.Rows[iR][sKeyName].ToString();
                                //取得主键的value--
    switch(AccDT.Rows[iR]["state_bak"].ToString())
    {//---s-------连接到sql
    case "I_N"://插入新的记录,先插入主表,再插入从表
    InsertRToSQL(sTblName,strCol,strColValue);
    break;
    case "U_O"://删除update的原记录,先删除从表,再删除主表
    delRFromSQL(sTblName,sKeyName,sKNValue);
    break;
    case "U_N"://插入update后的记录
    InsertRToSQL(sTblName,strCol,strColValue);
    break;
    case "D_O"://删除的记录
    delRFromSQL(sTblName,sKeyName,sKNValue);
    break; }//---s

    }//--3

    }//--2
    }//--1
      

  2.   

    既然这样,你应该检查
    iRcdCnt=GetRecordCount(sTblName);//取得表里记录的个数;
    是不是这个函数的问题,使你得到的iRcdCnt有时返回值为1,致使你的循环只执行了一次呢?
    你没有贴出这个函数,所以没有办法判断了。
      

  3.   

    大家帮忙看看吧,我实在是晕了。要是所有的表不行,还好些,现在是有的可以,有的不可以。同事有的说是代码的问题,有的说是sql不支持access的一些字段的原因,可我把这个access里的东西删的就剩下char还是不行(再注:别的表是可以的),也不知道是这个表有原因,还是别的问题。真的是难受。
    本来想要推倒重来,但想到要建触发器就发憷。
    急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      

  4.   

    这个iRcdCnt=GetRecordCount(sTblName);//取得表里记录的个数;
    取出来的数是正确的,不正确的原因是,在取列的values值时,只能取的一个列的values,别的都是空的。这样添加到数据库中也就只有一列加上了,别的列值就没
      

  5.   

    iFldCount=Convert.ToInt32(GetFldNameCount(sTblName));//取得字段个数???
    函数?贴出来
      

  6.   

    lemong(風之影):null有影响读取数据吗?可是我在所有的项里都添加了内容。
      

  7.   

    public string GetFldNameCount(string strTblName)
    {
    //string strDSN=LinkSqlData();
    string strSQL="select Count(*) as aaaCount from sysobjects t1,syscolumns t2 where t1.id=t2.id and t1.xtype='u' and t1.name='"+strTblName+"'";
    SqlConnection myConn = new SqlConnection(strDSN);
    SqlCommand myComm=new SqlCommand(strSQL,myConn);
    myConn.Open();
    string R_str=myComm.ExecuteScalar().ToString();
    myConn.Close();
    return R_str;

    }
    //---------连接SQL数据库----------
    public string LinkSqlData()
    {
    string strSqlDSN="Persist Security Info=False;Data Source=localhost;Initial Catalog=tjgp1;User ID=sa;Password=;";
    return strSqlDSN;
    }
      

  8.   

    我这里运行是没有问题的,你检查下是否表的列名或表名取了关键字的名字
    另外你上面的
    //string strDSN=LinkSqlData();
    所以取到的strDSN可能不正确。
      

  9.   

    我在使用前做了一个调用,那个在哪个datacoherence1()的前面定义的。
    还真的是有关键字,取了一个name。
      

  10.   

    我把这个name的名字改了,还是一样的问题,也不知道是什么原因?
      

  11.   

    你在SQL查询分析器中运行
    select Count(*) as aaaCount from sysobjects t1,syscolumns t2 where t1.id=t2.id and t1.xtype='u' and t1.name='   '
    看看结果是多少,并检查出问题的表和列
      

  12.   

    是不是那个table没有清空的原因?
    那我要再次fill的话,我怎样清空呢?
      

  13.   

    dataset.Tables["datatablename"].Clear();
    datatablename.Clear();
      

  14.   

    GetFldName函数的代码呢,建议把所有相关的代码贴出来,另外,最好不要使用这么多的内签循环,出了问题很难查的
      

  15.   

    谢谢大家,这个问题已经解决了就是没有清空table的原因