Use this
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace test
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
void Button1Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"User ID=username; Password=pass;
Initial Catalog=databasename; data source=localhost");
SqlCommand cmd = conn.CreateCommand();
foreach(ListItem i in listBox1.SelectedItem)
{
cmd.CommandText = "INSERT INTO TableName (columnName) VALUES('"+i.Text)+"')";
cmd.ExecuteNonQuery();
}
conn.Close();
}
}
Plz accept and vote otherwise revert back with your answer
--Rahul D.