我与数据库建立了连接,并且执行了查询以获取表中特定字段的结果,但是读者却没有输入一段时间,为什么?
public void connect()
{
string connStr = @"Server=xx98.66;Port=xx6;Database=sxxt;Uid=axx;Pwd=admxxx3z;";
MySqlConnection conn = new MySqlConnection(connStr);
try
{
Console.WriteLine("Connecting to MySQL...");
conn.Open();
string stm = "SELECT lastUpdated from soccerseason WHERE caption = 'Eredivisie 2015/1'";
MySqlCommand cmd = new MySqlCommand(stm, conn);
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Console.WriteLine("stdrstrr" + rdr.GetString(0));
}
Console.WriteLine("Connection successfull !");
conn.Close();
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("Eccezione => " + ex.ToString());
}
Console.WriteLine("Done.");
}
}
最佳答案
我认为这对您有帮助
包括这个
using MySql.Data.Common;
using MySql.Data.Types;
using MySql.Data.MySqlClient;
略微更改代码并检查
{
string connStr = @"Server=xx98.66;Port=xx6;Database=sxxt;Uid=axx;Pwd=admxxx3z;";
MySqlConnection conn = new MySqlConnection(connStr);
try
{
string stm = "SELECT lastUpdated from soccerseason WHERE caption = 'Eredivisie 2015/1'";
MySqlCommand cmd= conn.CreateCommand();
cmd.CommandText = @"SELECT lastUpdated from soccerseason WHERE caption = 'Eredivisie 2015/1'";
MySqlDataReader rdr;
conn.Open();
rdr= cmd.ExecuteReader();
DataTable dtsoccer= new DataTable();
dtsoccer.Load(rdr);
foreach (DataRow row in dtsoccer.Rows)
{
Console.WriteLine(row["lastUpdated "].ToString());
}
conn.Close();
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine("Eccezione => " + ex.ToString());
}
Console.WriteLine("Done.");
}
}