Well you don't show how many columns you have or what type they are, so I can only give general advice.
Also I know nothing about your database structure.
One way you can solve this problem is to create a
DataTable
that reflects the structure in your database.
DataTable dt = new DataTable();
dt.Columns.Add("Column1", typeof(int));
dt.Columns.Add("Column2", typeof(string));
dt.Columns.Add("Column3", typeof(double));
Then you go through the list view in a loop and add rows to your data table.
foreach (ListViewItem item in listView1.Items)
{
DataRow drNew = dt.NewRow();
drNew["Column1"] = int.Parse(item.SubItems[0].Text);
drNew["Column2"] = item.SubItems[0].Text;
drNew["Column3"] = double.Parse(item.SubItems[0].Text);
dt.Rows.Add(drNew);
}
dt.AcceptChanges();
If you want to save the data as XML, you just use this code line:
dt.WriteXml(@"C:\SomeFolder\SomeFileName.xml");
This is one simplistic way to save the data into the database
string sql = "INSERT INTO table_name (Column1, Column2, Column3) VALUES (@col1, @col2, @col3)";
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
foreach (DataRow dr in dt.Rows)
{
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
cmd.Parameters.AddWithValue("@col1", dr["Column1"]);
cmd.Parameters.AddWithValue("@col2", dr["Column2"]);
cmd.Parameters.AddWithValue("@col3", dr["Column3"]);
cmd.ExecuteNonQuery();
}
}
There are many other ways to do this.