multiple listboxes and values to a database.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have 4 listboxes which all contain data. My application inserts 4 textbox values to the listboxes at the same time. What I now want to do is insert all the values from all the listboxes at the same time into the database. So all the values from the listboxes
that have the same indexes need to be inserted in the same table at the same time. I managed to get the values from one listbox into the database but cant get the others to. Im using a stored proc to pass values from the listboxes to the sql database when
the web app iterates through the listboxes
<pre class="prettyprint try
{
System.Configuration.Configuration rootWebConfig =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/");
System.Configuration.ConnectionStringSettings connString;
connString =
rootWebConfig.ConnectionStrings.ConnectionStrings["IntercoConnectionString"];/*Name of connection in web.config file */
string conn1 = connString.ConnectionString;
SqlConnection conn = new SqlConnection(conn1);
conn.Open();

int value = 0;
for (int i = 0; i < ListBox1.Items.Count; i++)
{
value = 0;
SqlCommand cmd = new SqlCommand("quoteInsert", conn);
cmd.CommandType = CommandType.StoredProcedure;
value += Convert.ToInt32(ListBox1.Items.Text);
cmd.Parameters.AddWithValue("Height",value);
cmd.ExecuteNonQuery();
}

int value2 = 0;
for (int w = 0; w < ListBox2.Items.Count; w++)
{
value2 = 0;
SqlCommand cmd1 = new SqlCommand("quoteInsert", conn);
cmd1.CommandType = CommandType.StoredProcedure;
value2 += Convert.ToInt32(ListBox2.Items[w].Text);
cmd1.Parameters.AddWithValue("Breadth", value2);
cmd1.ExecuteNonQuery();
}
conn.Close();


}
catch (SqlException connError)
{
MessageBox.Show("Connection error, unable to connect to database", "Connection Status", MessageBoxButtons.OK, MessageBoxIcon.Error);
}[/code]
<br/>
<br/>


View the full article
 
Back
Top