在这段代码中,我在读取我的数据库阅读器从查询中获得的列时出错。错误在行中:
DbCom.CommandText = System.String.Format("INSERT into Cortex(IdDA,Vlsd) values({0},'yes')",DbReader.GetInt16(0));
他们说在 ligne 或 colomn 中不存在数据,但它确实存在。
public static void Main(string[] args)
{
using (OdbcConnection DbConnection = new OdbcConnection("DSN=savior"))
{
DbConnection.Open();
OdbcCommand DbCommand = DbConnection.CreateCommand();
DbCommand.CommandText = "SELECT IDA FROM Dchas";
try
{
DbReader = DbCommand.ExecuteReader();
int fCount = DbReader.FieldCount;
if (fCount > 0)
{
do
{
using (OdbcConnection DbConnect = new OdbcConnection("DSN=savior"))
{
DbConnect.Open();
OdbcCommand DbCom = DbConnect.CreateCommand();
DbCom.CommandText = System.String.Format("INSERT into Cortex(IdDA,Vlsd) values({0},'yes')",DbReader.GetInt16(0));
try
{
DbCom.ExecuteNonQuery();
}
catch (OdbcException ex)
{
Console.WriteLine("Executing the query2 failed.");
Console.WriteLine("The OdbcCommand returned the following message");
Console.WriteLine(ex.ToString());
return;
}
}
} while (DbReader.Read());
}
else
{
Console.WriteLine("Query affected row(s)");
return;
}
}
catch (OdbcException ex)
{
Console.WriteLine("Executing the query1 failed.");
Console.WriteLine("The OdbcCommand returned the following message");
Console.WriteLine(ex.ToString());
return;
}
}
}