gpt4 book ai didi

c# - 数据库架构已更改

转载 作者:太空狗 更新时间:2023-10-30 00:50:19 24 4
gpt4 key购买 nike

我不断收到此错误 database schema has changed near "1": syntax error

我不会更改代码中的模式。这是我制作模式的代码。希望尝试每个答案以便您发布它。此代码用于将数据库传输到另一个数据库程序。所以它必须兼容不止一个数据库程序。

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 .... LIMIT 1

而不是 SELECT TOP 1 *

关于c# - 数据库架构已更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32346105/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com