none
错误 CS0029 无法将类型“System.Data.DataTable”隐式转换为“string” RRS feed

  • Question

  • 错误 CS0029 无法将类型“System.Data.DataTable”隐式转换为“string”,我想将数据表中离当前时间最近的一条数据实时显示在标签上,该怎么改呢?希望大神们提供下修改后的源代码。谢谢了!

    private void Form1_Load(object sender, EventArgs e)
            {
                MySQL57 con = new MySQL57();
                String sql1 = "select * from TemperatureAndHumidity where time = (select time from TemperatureAndHumidity order by time desc limit 1)";
                dataGridView1.DataSource = con.ExecuteQuery(sql1);
                String sql2 = "select * from LightIntensity where time = (select time from LightIntensity order by time desc limit 1)";
                dataGridView2.DataSource = con.ExecuteQuery(sql2);
                String sql3 = "select * from Pump where time = (select time from Pump order by time desc limit 1)";
                dataGridView3.DataSource = con.ExecuteQuery(sql3);
                String sql4 = "select * from WaterLevel where time = (select time from WaterLevel order by time desc limit 1)";
                dataGridView4.DataSource = con.ExecuteQuery(sql4);
                String sql5 = "select * from CO2  where time = (select time from CO2 order by time desc limit 1)";
                dataGridView5.DataSource = con.ExecuteQuery(sql5);

              
                label2.Text = con.ExecuteQuery(sql1);
            }

    • Moved by Baron Bi Monday, July 10, 2017 9:48 AM
    • Moved by CoolDadTx Monday, July 10, 2017 1:48 PM Wrong locale
    Monday, July 10, 2017 7:19 AM

All replies

  • Hi cys1628,

    Thanks for posting here.

    This forum is about c++ development. For your case, I will move it to c# forum for better support.

    Your understanding and cooperation will be grateful.

    Best Regards,

    Sera Yu


    MSDN Community Support<br/> Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact <a href="mailto:MSDNFSF@microsoft.com">MSDNFSF@microsoft.com</a>.


    • Edited by Baron Bi Monday, July 10, 2017 9:46 AM
    Monday, July 10, 2017 9:45 AM
  • These forums are for English questions only. Please either post your question in English or post your question in the forums appropriate for your locale.
    Monday, July 10, 2017 1:48 PM