首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >数据库模式已更改

数据库模式已更改
EN

Stack Overflow用户
提问于 2015-09-02 06:34:09
回答 3查看 4.8K关注 0票数 5

我一直收到这个错误database schema has changed near "1": syntax error

我不会在代码中更改我的架构。这是我制定模式的代码。希望尝试每一个答案,以便您张贴它。此代码用于将数据库传输到另一个数据库程序。因此,它必须与多个数据库程序兼容。

代码语言:javascript
复制
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模式已经更改了arror的部分。

代码语言:javascript
复制
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);
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-09-02 06:43:57

我相信你需要使用的不是SELECT TOP 1 *,而是SELECT * FROM .... LIMIT 1

票数 5
EN

Stack Overflow用户

发布于 2015-09-02 06:45:46

您需要检查nameTable为空还是空

代码语言:javascript
复制
if(!string.IsNullOrEmpty(fullTableName))
 string sql = string.Format("SELECT * FROM {0} LIMIT 1", fullTableName);

SQLLITE的

代码语言:javascript
复制
SELECT * FROM Table_Name LIMIT 1;

for SQL

代码语言:javascript
复制
SELECT TOP 1 * FROM Table_Name;
票数 1
EN

Stack Overflow用户

发布于 2015-09-02 06:56:46

你能试试这个吗?

代码语言:javascript
复制
SELECT * FROM SAMPLE_TABLE ORDER BY ROWID ASC LIMIT 1
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32346105

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档