gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 10:46:47 24 4
gpt4 key购买 nike

我用ASP.NET查询MYSQL数据库

但是他没有出现。只有"waiting for localhost'我等了,但是没变

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

---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 = "SELECT NAME FROM playdata WHERE SID = '001'";String cmdText = "SELECT NAME FROMtestdb.playdata WHERE SID = '001' ";String cmdText = "SELECT NAME FROM playdata WHERE SID = '001'";

最佳答案

将查询更新为:

String cmdText = "SELECT NAME FROM playdata WHERE SID = 'S01'";

您插入了 SID“S01”并且之前查询的是 SID“001”

关于c# - ASP.NET (C#) 查询 MYSQL 无响应,永远等待 localhost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30554214/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com