我可以让其他查询工作,但我无法让这个查询在 Visual Studio 中工作假设 ConnectionString 在这个函数之外声明
公共数据表GetDtSearch(字符串搜索名){
string sql = "SELECT * FROM table WHERE (file_name LIKE @searchname)";
DataTable dt = new DataTable();
using (MySqlConnection con = new MySqlConnection(ConnectionString))
{
try
{
con.Open();
}
catch { return dt; }
using (MySqlCommand cmd = new MySqlCommand(sql, con))
{
cmd.Parameters.Add(@searchname,"%"+ searchname+"%");
using (MySqlDataAdapter adp = new MySqlDataAdapter(cmd))
{
try
{
adp.Fill(dt);
}
catch
{
}
}
}
con.Close();
}
return dt;
}