How to insert record into database from list view control using C#.Net



In this article i will describe how to insert record into database from Listview control using C#.Net.


In the Previous articles i explained how to delete record from access database using vb.nethow to add namespace in vb.netredirect to page according to role while login in asp.nethow to open form on click of the button using, how to close form on click of the button using and many more about C#.Net.

Step 1.

Drag and Drop a button and Listview control on Form.

Step 2.

Write the following code on click event of the Button.

foreach (ListViewItem li in listView1.Items)
               OleDbCommand cmd = new OleDbCommand("insert into bookings (code,client_name)values('" + li.SubItems[0].Text + "','" + li.SubItems[1].Text + "');", con);


Here i am inserting data into bookings table from Listview. Here foreach loop will run till the last row of list view control.

Give your Valuable Comments.
comments powered by Disqus
Follow me on twitter
About Me
Harpreet Singh
I began programming with C++ when i was 17. Then at the middle of my study .NET came. Then I began to read C# and VB.NET. By the time i learnt SQL and ASP.NET, and developed some websites such as news portals that are active now. Currently i am running my own Software company.
More Articles