所以这是我的代码,我真的不知道为什么它可以在其他程序中工作,这个代码是标准的!
static void Main(string[] args)
{
using (OdbcConnection DbConnection = new OdbcConnection("DSN=savior"))
{
String query = "***";
OdbcCommand DbCommand = DbConnection.CreateCommand();
DbCommand.CommandText = query;
try
{
OdbcDataReader DbReader = DbCommand.ExecuteReader();
do
{
int fCount = DbReader.FieldCount;
if (fCount > 0)
{
while (DbReader.Read())
{
using (OdbcConnection DbConnect = new OdbcConnection("DSN=savior"))
{
OdbcCommand DbCom = DbConnect.CreateCommand();
query = System.String.Format("***", DbReader.GetInt16(0));
DbCom.CommandText = query;
try
{
DbCom.ExecuteNonQuery();
}
catch (OdbcException ex)
{
Console.WriteLine("Executing the query2 failed.");
Console.WriteLine("The OdbcCommand returned the following message");
Console.WriteLine(ex.Message);
return;
}
}
}
}
else
{
Console.WriteLine("Query affected row(s)");
}
}
while (DbReader.NextResult());
DbReader.Close();
}
catch (OdbcException ex)
{
Console.WriteLine("Executing the query1 failed.");
Console.WriteLine("The OdbcCommand returned the following message");
Console.WriteLine(ex.Message);
return;
}
}
}
它给了我以下错误,我已经尝试了很多开始和连接的置换,但没有任何 goog 结果。
代码编辑:
static void Main(string[] args)
{
using (OdbcConnection DbConnection = new OdbcConnection("DSN=savior"))
{
DbConnection.Open();
OdbcCommand DbCommand = DbConnection.CreateCommand();
DbCommand.CommandText = "select ID from Table where ID not in (select IdDA from Seconde)";
try
{
OdbcDataReader DbReader = DbCommand.ExecuteReader();
do
{
int fCount = DbReader.FieldCount;
if (fCount > 0)
{
while (DbReader.Read())
{
using (OdbcConnection DbConnect = new OdbcConnection("DSN=savior"))
{
DbConnect.Open();
OdbcCommand DbCom = DbConnect.CreateCommand();
DbCom.CommandText = System.String.Format("INSERT into Seconde(IdDA,Validee) values({0},'oui')", 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.Message);
return;
}
}
}
}
else
{
Console.WriteLine("Query affected no row(s)");
}
}
while (DbReader.NextResult());
}
catch (OdbcException ex)
{
Console.WriteLine("Executing the query1 failed.");
Console.WriteLine("The OdbcCommand returned the following message");
Console.WriteLine(ex.Message);
return;
}
}
}