How to save all the items from a listview into a access database

I have the following fields in my table called Question_paper
Questionno
Subjectcode
Subjectname
Questionname
Optiona
Optionb
Optionc
Optiond

and the same is in the listview

How do I now save all the items in the listview into my access database

Thank you
Posted by Mark Dsouza 2/18/2015 1:07:07 PM
Total Answers : 1
Answer 1
Dear Mark, You can do it like the following way :


OleDbConnection sr = new OleDbConnection("connectionstring");
sr.Open();

foreach (ListViewItem li in listView1.Items)
{

String sqlr = "insert into tablename(column1,column2)values('" + li.SubItems[0].Text + "','" + li.SubItems[1].Text + "')";
new OleDbCommand(sqlr, sr).ExecuteNonQuery();


}



sr.Close();
MessageBox.Show("Record Saved Successfully.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);


Enjoy and keep in touch with StepCoder.
Posted by StepCoder Team 2/21/2015 9:42:21 AM
Post your answer
Preview
Sign in to your account
Your Email : 
Password :   
Forgot your password
Don't have StepCoder account ?
Create a new account
 
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.
Answer these questions! If you know the answer.