Hi,
suppose your list box is Employee ListBox then to insert all emp records into DB call the following method on Save Button click:
public void SavValues()
{
SqlConnection connectionSql = new SqlConnection("Data Source=(local);Integrated Security=sspi");
SqlCommand commandSql = new SqlCommand();
commandSql.Connection = connectionSql;
commandSql.CommandText = "INSERT INTO dbo.Employee (EmployeeName) VALUES (@employeeName)";
commandSql.Parameters.Add("@employeeName");
try
{
connectionSql.Open();
for (int indexCounter = 0; indexCounter < listBoxEmployeeName.Items.Count; indexCounter++)
{
commandSql.Parameters["employeeName"].Value = listBoxEmployeeName.Items[indexCounter].Text;
commandSql.ExecuteNonQuery();
}
connectionSql.Close();
}
catch (Exception exceptionMessage)
{
}
finally
{
commandSql.Dispose();
connectionSql.Close();
connectionSql.Dispose();
}
}