C# 数据库架构已更改

C# 数据库架构已更改,c#,sqlite,C#,Sqlite,我不断发现这个错误数据库模式在“1”附近发生了更改:语法错误 我没有在代码中更改我的模式。 这是我创建模式的代码。 希望尝试每个答案,以便您发布它。 此代码用于将数据库传输到另一个数据库程序。 因此,它必须与多个数据库程序兼容 public DataTable GetSchemaTable(string schema, string nameTable) { switch (m_dbType) { case dbTypeEnum.S

我不断发现这个错误
数据库模式在“1”附近发生了更改:语法错误

我没有在代码中更改我的模式。 这是我创建模式的代码。 希望尝试每个答案,以便您发布它。 此代码用于将数据库传输到另一个数据库程序。 因此,它必须与多个数据库程序兼容

public DataTable GetSchemaTable(string schema, string nameTable)
    {
        switch (m_dbType)
        {
            case dbTypeEnum.Sqlite:
                //Make the schema of the source table
                MakeConnectionString();
                string fullTableName = schema.Length > 0
                    ? string.Format("[{0}].[{1}]", schema, nameTable)
                    : string.Format("[{0}]", nameTable);
                if (!string.IsNullOrEmpty(fullTableName))
                {
                    string sql = string.Format("SELECT * FROM {0} LIMIT 1", fullTableName);
                    DataTable dtSchemaSource;
                    try
                    {
                        using (IDataReader rdr = ReadOnlyForwardOnly(sql))
                        {
                            dtSchemaSource = rdr.GetSchemaTable();
                        }
                    }
                    finally
                    {
                        CloseConnection();
                    }
                    if (dtSchemaSource == null)
                    {
                        throw new RadGeneralException("rdr.GetSchemaTable() returns null with sql = " + sql);
                    }

                    return dtSchemaSource;
                }
                break;

            default:
                //Make the schema of the source table
                MakeConnectionString();
                string fullTableName = schema.Length > 0
                    ? string.Format("[{0}].[{1}]", schema, nameTable)
                    : string.Format("[{0}]", nameTable);
                string sql = string.Format("SELECT TOP 1 * FROM {0}", fullTableName);
                DataTable dtSchemaSource;
                try
                {
                    using (IDataReader rdr = ReadOnlyForwardOnly(sql))
                    {
                        dtSchemaSource = rdr.GetSchemaTable();
                    }
                }
                finally
                {
                    CloseConnection();
                }
                if (dtSchemaSource == null)
                {
                    throw new RadGeneralException("rdr.GetSchemaTable() returns null with sql = " + sql);
                }
                return dtSchemaSource;

        }
    }
这是sqlite模式发生更改或出现错误的部分

StringBuilder sbColList = new StringBuilder();
        nCol = 0;
        identityColInBothTables = false;
        //Make the schema of the source table
        DataTable dtSchemaSource = objDbSource.GetSchemaTable(SchemaSource, Name);
        //Make the schema of the target table
        DataTable dtSchemaTarget = objDbTarget.GetSchemaTable(SchemaTarget, Name);

我认为您需要使用
SELECT*FROM…,而不是
SELECT TOP 1*
。。。。限制1

您需要检查nameTable是否为空

if(!string.IsNullOrEmpty(fullTableName))
 string sql = string.Format("SELECT * FROM {0} LIMIT 1", fullTableName);
用于SQLLITE

SELECT * FROM Table_Name LIMIT 1;
用于SQL

SELECT TOP 1 * FROM Table_Name;
你能试试这个吗

SELECT * FROM SAMPLE_TABLE ORDER BY ROWID ASC LIMIT 1

TOP 1
在中是无效语法sqlite@Fred谢谢更新+抛出:“靠近“1”的语法不正确”。(System.Data.SqlClient.SqlException)异常消息=“靠近“1”的语法不正确”,异常类型=“System.Data.SqlClient.SqlException”,异常WinRT Data=null仍然得到错误长话短说这对我有帮助。仍然会出现新的错误:)在调用ExecuteReader()时是否可以检查字符串查询如果
LIMIT
解决方案仍然存在问题,那么您也应该发布
ReadOnlyForwardOnly
GetSchemaTable
代码。