日期:2014-05-17  浏览次数:20979 次

C#链接mysql
我测试了下,sql语句没错,放到数据库里 有记录出来,链接什么的也没报错,数据库链接正常,但是我返回的dt是null
public DataTable getWX(string tname)
        {
                string sql = "select stoptime,spe,TimeStampDiff(SECOND,gpstime,now()) servertime,model,gpstime,lon,lat from tb_terminal where tName='" + tname + "'";
                return DBAccess.getDataMySql(sql, "mySql");
        }


public static DataTable getDataMySql(string sql, string connString)
        {
            using (MySqlConnection conn = new MySqlConnection(connectionString(connString)))
            {
                using (MySqlCommand comm = new MySqlCommand(sql, conn))
                {
                    DataTable dt = new DataTable();
                    try
                    {
                        conn.Open();
                        MySqlDataAdapter sda = new MySqlDataAdapter();
                        sda.SelectCommand = comm;
                        sda.Fill(dt);
                    }
                    catch (Exception) { throw; }
                    finally
                    {
                        comm.Parameters.Clear();
                        comm.Dispose();
                        conn.Close();
                    }
                    return dt;
      &