How to Save the records of Listview to SqlServer Db?

Posted by Sapna under VB.NET on 12/27/2009 | Views : 4185 | Status : [Member] | Replies : 3
i have taken 2 textboxes and i Listview.
On button click i pass these textbox values to Listview.
But I now want to save the number of records in SQLServer db.
Please Help.
IT'S URGENT




Responses

Posted by: Virendradugar on: 12/28/2009 [Member] [MVP] Silver

Up
0
Down
Hi,

There are two ways of doing this:

1. You can loop through the list view and can insert records one by one.

2. Create a comma separated string of all the records and pass it to stored procedure. Split the string and insert records in the table.

Thank you for posting @ DotnetFunda.

Thanks,
Virendra Dugar.

Sapna, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sagarp on: 1/2/2010 [Member] Bronze

Up
0
Down
Ref This link


http://www.vsj.co.uk/dotnet/display.asp?id=734

Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Sapna, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 1/7/2010 [Member] Bronze

Up
0
Down
Try the following code.

string conStr = 'Con string';


SqlConnection con = new SqlConnection(conStr);
con.Open();
for (cnt = 0; cnt <= listView1.SelectedItems.Count - 1; cnt++)
{
string query = "insert into table values('" + listView.Items[cnt].Text + "')";
SqlCommand cmd = new SqlCommand(query, con);
retval=cmd.ExecuteNonQuery();
}
con.Close();


Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Sapna, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response