Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET(C)查询MYSQL无响应,永远等待localhost_C#_Mysql_Asp.net - Fatal编程技术网

C# ASP.NET(C)查询MYSQL无响应,永远等待localhost

C# ASP.NET(C)查询MYSQL无响应,永远等待localhost,c#,mysql,asp.net,C#,Mysql,Asp.net,我使用ASP.NET查询MYSQL数据库 但他没有露面。只是在等待localhost'I等待,但没有改变 但同样的代码在形式上是可行的 --ASP.NET protected void Button3_Click(object sender, EventArgs e) { string connStr = "server=localhost;port=3306;uid=root;pwd=123123;database=testdb;"; MySqlConnection conn

我使用ASP.NET查询MYSQL数据库

但他没有露面。只是在等待localhost'I等待,但没有改变

但同样的代码在形式上是可行的

--ASP.NET

protected void Button3_Click(object sender, EventArgs e)
{
    string connStr = "server=localhost;port=3306;uid=root;pwd=123123;database=testdb;";
    MySqlConnection conn = new MySqlConnection(connStr);
    MySqlCommand command = conn.CreateCommand();
    try
    {
        conn.Open();
        String cmdText = "SELECT NAME FROM playdata WHERE SID = '001'";
        command = new MySqlCommand(cmdText, conn);
        SL1.Text = (string)command.ExecuteScalar();
    }
    catch (MySql.Data.MySqlClient.MySqlException ex)
    {
        switch (ex.Number)
        {
            case 0:
                SL1.Text = "Can not connect";
                break;
            case 1045:
                SL1.Text = "Input error";
                break;
        }
    }
    Console.ReadLine();
    conn.Close();
}
我不知道如何解决这个问题,在ASP.NET中,插入数据是成功的 所以我不知道哪里错了

--插入数据

    string connStr = "server=localhost;port=3306;uid=root;pwd=123123;database=testdb;";
    MySqlConnection conn = new MySqlConnection(connStr);
    MySqlCommand command = conn.CreateCommand();
    try
    {
        conn.Open();
        command.CommandText = "INSERT INTO `testdb`.`playdata` (`SID`, `NAME`,`PWD`,`EMAIL`) VALUES('S01', 'MYNAME','RRR01','E4913')"; //重點
        command.ExecuteNonQuery();
    }
    catch (MySql.Data.MySqlClient.MySqlException ex)
    {
        switch (ex.Number)
        {
            case 0:
                SL1.Text ="Connection fail";
                break;
            case 1045:
                SL1.Text ="pwd error.";
                break;
        }
    }
    Console.ReadLine();
    conn.Close();
*编辑 我使用visual studio community 2015 我试过了 127.0.0.1 本地服务器 String cmdText=从播放数据中选择名称,其中SID='001'; String cmdText=从testdb.playdata中选择名称,其中SID='001';
String cmdText=从播放数据中选择名称,其中SID='001'

将您的查询更新为:

 "SELECT NAME FROM `testdb`.`playdata` WHERE SID = '001'";

我对php中的撇号有意见。可能是相同的问题。

将您的查询更新为:

 "SELECT NAME FROM `testdb`.`playdata` WHERE SID = '001'";
我对php中的撇号有意见。可能是相同的问题。

将查询更新为:

String cmdText = "SELECT NAME FROM playdata WHERE SID = 'S01'";
您插入了SID“S01”,并且之前正在查询SID“001”

将查询更新为:

String cmdText = "SELECT NAME FROM playdata WHERE SID = 'S01'";
您插入了SID“S01”,并且之前查询了SID“001”

我尝试了又尝试了更多的教学,我发现此代码是有效的! 问题的原因来自Console.ReadLine

谢谢大家帮助我

我尝试了又尝试了更多的教学,我发现这个代码是有效的! 问题的原因来自Console.ReadLine


谢谢大家帮助我

用这个testdb.playdata替换你的playdata,我试过了,但它没有改变,这个更改表单有效,但是ASP.NET仍然“for local”SID使用的数据类型是什么?他是“VARCHAR 45”,有人有同样的问题吗?用这个testdb.playdata替换你的playdata,我试过了,但没有改变,这个更改表单有效,但是ASP.NET仍然“for local”SID使用的数据类型是什么?他是“VARCHAR 45”有人有同样的问题吗?我试过了,但没有改变,这在formI-Treaded中也是有效的,但没有改变,这在formI-Treaded中也是有效的,但再次进入等待,是在工作台“001”中输入的值吗,“S01”用于测试插入,该值在formI中有效,但在等待中,输入的是工作台“001”中的值,“S01”用于测试插入,该值在表单中有效