The Display_Form_Load() Function is working fine.
private void Display_Form_Load(object sender, EventArgs e)
{
try
{
using (SqlConnection cn = new
SqlConnection("Server=ZIKO_RED2486;Database=Students;Integrated Security=true"))
{
if (cn.State == ConnectionState.Closed)
cn.Open();
using (SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Student", cn))
{
da.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Id_Student
is the name of the column in The Table.
I want to search by id so txt_Search_Id
is the input:
private void Search_Click(object sender, EventArgs e)
{
DataView DV = dt.DefaultView;
DV.RowFilter = string.Format("CONVERT(Id_Student, System.String) like '%{0}%'",
txt_Search_Id);
dataGridView1.DataSource = DV.ToTable();
}
When I click this Button, the search should be done, instead all the rows are removed from the DGV.
I was expecting to see the Rows filtered by the txt_Search_Id
value.
I wish someone correct what i did wrong.