Using Csharp Listview Object

While working with C#, let’s talk a little bit about the Listview object that presents the data you pull from the database to the user by pouring it into the table.
Listview Object
First of all, let’s create the Listview object from the Toolbax section of the Visual Studio program by dragging it onto the form.
After making the necessary sizing, click the right arrow button at the top right of the listview object and click the“Edit Columns” link in the window that opens. After determining the columns of the fields we will pull from the database and the titles of these columns, we will come to the click event of the button that will run the program and write the codes as follows.
<span style="color: #0000ff;">Public Static Void </span>button1_Click(<span style="color: #0000ff;">object </span>sender, <span style="color: #008000;">EventArgs</span> e)
{
list_dokum.Items.Clear();
<span style="color: #008000;">SqlConnection</span> con = <span style="color: #0000ff;">new</span> <span style="color: #008000;">SqlConnection</span>(<span style="color: #993300;">"server=localhost;database=dbase;user id=sa;password=123456"</span>);
<span style="color: #008000;">SqlCommand </span>cmd = <span style="color: #0000ff;">new</span> <span style="color: #008000;">SqlCommand</span>(<span style="color: #993300;">"SELECT * FROM tablo WHERE soyadi LIKE '" + txt_soyadi.Text + "%'AND dogum_tarih LIKE '" + txt_dogum.Text + "%' ORDER BY id DESC"</span>, con);
con.Open();
<span style="color: #008000;">SqlDataReader</span> rdr = cmd.ExecuteReader();
if (rdr.HasRows)
{
while (rdr.Read())
{
<span style="color: #008000;">ListViewItem</span> lst = new <span style="color: #008000;">ListViewItem</span>();
lst.Text = rdr[<span style="color: #993300;">"v_no"</span>].ToString();
lst.SubItems.Add(rdr[<span style="color: #993300;">"adi"</span>].ToString());
lst.SubItems.Add(rdr[<span style="color: #993300;">"soyadi"</span>].ToString());
lst.SubItems.Add(rdr[<span style="color: #993300;">"babaadi"</span>].ToString());
lst.Tag = rdr["id"];
list_dokum.Items.Add(lst);
}
}HTMLMAKE A COMMENT
COMMENTS - 0 COMMENTS




