【发布时间】:2023-03-23 17:46:02
【问题描述】:
在我的窗口表单中,我使用datagridview 向用户显示类别的详细信息,但我还想在我的表中没有找到记录时显示自定义消息,然后我想显示自定义消息,例如
“没有找到记录”。
此消息应该在 datagrird 视图中,就像您熟悉 asp 一样,其中有空的 data template 以在 gridview 中显示自定义消息
这是在我的datagridview中显示数据的代码
public void getData()
{
try
{
con = new SqlConnection(str);
con.Open();
string getAll = "select (CatID) as [ID],CategoryName as [Category Name] from Category order By CategoryName";
SqlCommand cmd = new SqlCommand(getAll, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Category");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = ds.Tables[0].ToString();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
and i called this method on form load.
【问题讨论】:
标签: c# sql-server winforms datagridview