它只显示列但数据没有出现......?请帮帮我 [英] Its only showing the columns but data is not appearing...? Please help me on this
本文介绍了它只显示列但数据没有出现......?请帮帮我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public partial class Window_search:Window
{
public Window_search()
{
InitializeComponent();
}
private void Search_button_Click_1(对象发送者,RoutedEventArgs e)
{
var id = Device_id_TextBox.ToString();
MySqlConnection con = new MySqlConnection(database);
con.Open();
DataTable devicetable = new DataTable();
MySqlDataAdapter adapter = new MySqlDataAdapter(SELECT`Device_ID`,`Device_Name`,`Devic_Category`,`Status`,`Description`,`Customer_ID`,`Customer_Name` FROM`devicedetails` WHERE`Device_ID` ='id ,CON);
尝试
{
adapter.Fill(devicetable);
table_grid_view.DataContext = devicetable;
con.Close();
}
catch(Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
< pre lang = c#>< pre lang = c# >
我尝试过:
公共部分类Window_search:Window
{
public Window_search()
{
InitializeComponent();
}
private void Search_button_Click_1(对象发送者,RoutedEventArgs e)
{
var id = Device_id_TextBox.ToString();
MySqlConnection con = new MySqlConnection(database);
con.Open();
DataTable devicetable = new DataTable();
MySqlDataAdapter adapter = new MySqlDataAdapter(SELECT`Device_ID`,`Device_Name`,`Devic_Category`,`Status`,`Description`,`Customer_ID`,`Customer_Name` FROM`devicedetails` WHERE`Device_ID` ='id ,CON);
尝试
{
adapter.Fill(devicetable);
table_grid_view.DataContext = devicetable;
con.Close();
}
catch(Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
解决方案
查看你的代码:
MySqlDataAdapter adapter = new MySqlDataAdapter(SELECT`Device_ID`,`Device_Name`,`Devic_Category`,`Status`,`Description `,`Customer_ID`,`Customer_Name` FROM`devicedetails` WHERE`Device_ID` ='id',con);
您只获取与显式和固定条件匹配的记录:
Device_ID
列包含字符串id。如果没有列匹配 - 我非常怀疑是否有 - 你将没有返回任何行。
可能你想传递一个ID值作为参数查询并返回匹配的行,而不是固定的字符串:参数化查询MySQL | @Henning [ ^ ]
public partial class Window_search : Window { public Window_search() { InitializeComponent(); } private void Search_button_Click_1(object sender, RoutedEventArgs e) { var id = Device_id_TextBox.ToString(); MySqlConnection con = new MySqlConnection("database"); con.Open(); DataTable devicetable = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT `Device_ID`, `Device_Name`, `Devic_Category`, `Status`, `Description`, `Customer_ID`, `Customer_Name` FROM `devicedetails` WHERE `Device_ID` = 'id'",con); try { adapter.Fill(devicetable); table_grid_view.DataContext = devicetable; con.Close(); } catch (Exception Ex) { MessageBox.Show(Ex.Message); } } }
<pre lang="c#"><pre lang="c#">
What I have tried:
public partial class Window_search : Window { public Window_search() { InitializeComponent(); } private void Search_button_Click_1(object sender, RoutedEventArgs e) { var id = Device_id_TextBox.ToString(); MySqlConnection con = new MySqlConnection("database"); con.Open(); DataTable devicetable = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT `Device_ID`, `Device_Name`, `Devic_Category`, `Status`, `Description`, `Customer_ID`, `Customer_Name` FROM `devicedetails` WHERE `Device_ID` = 'id'",con); try { adapter.Fill(devicetable); table_grid_view.DataContext = devicetable; con.Close(); } catch (Exception Ex) { MessageBox.Show(Ex.Message); } } }
解决方案
Look at your code:
MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT `Device_ID`, `Device_Name`, `Devic_Category`, `Status`, `Description`, `Customer_ID`, `Customer_Name` FROM `devicedetails` WHERE `Device_ID` = 'id'",con);You are fetching only records which match an explicit and fixed condition: that the
Device_ID
columns contains the string "id". If no columns match that - and I very much doubt if any do - you will get no rows returned.
Probably, you wanted to pass an ID value as a parameter to the query and return matching rows, rather than a fixed string: Parameterized queries in MySQL | @Henning[^]
这篇关于它只显示列但数据没有出现......?请帮帮我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文