gpt4 book ai didi

c# - 执行Mysql查询时命令执行过程中遇到 fatal error

转载 作者:行者123 更新时间:2023-11-29 16:31:23 26 4
gpt4 key购买 nike

在C#中执行Mysql查询时在命令执行过程中遇到 fatal error

db.cs

 public  static void openconn()
{
try
{

if (conn.State == ConnectionState.Closed)
{
conn.Open();
}



}
catch (MySqlException ex)
{
if (conn.State != ConnectionState.Open)
{

conn.Dispose();

}
else
{
throw;
}


}

}



public static DataTable selectdata(string select)
{
DataTable tbl = new DataTable();
try
{

if (CheckForInternetConnection())
{
openconn();
if (conn.State == ConnectionState.Open)
{
dbcomm.CommandText = select;
tbl.Load(dbcomm.ExecuteReader());
}


return tbl;
}
else
{

return tbl;
}

}
catch (MySqlException ex)
{

MessageBox.Show(ex.Message);
return tbl;

}

}



public async static void runq(string sql)
{


try
{

if (conn.State == ConnectionState.Open)
{
dbcomm.CommandText = sql;
dbcomm.ExecuteNonQuery();
addActions(sql);
}
else
{
MessageBox.Show("خطأ بالاتصال بقاعدة البيانات");
}
}
catch (Exception ex)
{

MessageBox.Show( ex.Message);;
}






}

当您调用此函数时,您会收到错误消息在C#中执行Mysql查询时在命令执行过程中遇到 fatal error

   private void loadcolor()
{
try
{
if (!this.DesignMode)
{
db.openconn();
DataTable tbl = db.selectdata("select color_no,color_name from color");
cbxcolor.DataSource = tbl;
cbxcolor.ValueMember = "color_no";
cbxcolor.DisplayMember = "color_name";

}
}
catch (Exception)
{
`enter code here`////
}
}

如何解决这个问题?其中消息显示大约 90% 的函数调用命令执行

最佳答案

试试这个:

    public DataTable selectdata(string Qry)
{
try
{
var datatable = new DataTable();
conn.Open();
MySqlDataAdapter obj = new MySqlDataAdapter(Qry, conn);
obj.Fill(datatable);
conn.Close();
return datatable;
}
catch (MySqlException)
{
return new DataTable();
}
}

关于c# - 执行Mysql查询时命令执行过程中遇到 fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53847842/

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