Multiple dropdown list boxes into SQL database under button click event.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Please can anyone help ? I have three dropdown list boxes which are connected to a table with values 1-5. This is done using a sqlDataSource auto gen via Toolbox. I need the selected numbers from the dropdown list boxes to go into a seperate table in sql
server under a button click event(Button_At_Reg_Click). The code i have so far only includes two text boxes via sql server thank you in advance.
using System.Collections.Generic;<br/>
using System.Linq;<br/>
using System.Web;<br/>
using System.Web.UI;<br/>
using System.Web.UI.WebControls;<br/>
using System.Data;<br/>
using System.Data.SqlClient;<br/>
<br/>
<br/>
namespace ********<br/>
{<br/>
public partial class ******** : System.Web.UI.Page<br/>
{<br/>
SqlConnection con = new SqlConnection("****************************************************************");<br/>
SqlDataAdapter da;<br/>
SqlDataReader rdr;<br/>
SqlCommand cmd;<br/>
DataSet ds = new DataSet();<br/>
<br/>
protected void Page_Load(object sender, EventArgs e)<br/>
{<br/>
<br/>
}<br/>
<br/>
protected void Button_At_Reg_Click(object sender, EventArgs e)<br/>
{<br/>
<br/>
string str = "INSERT INTO IAR(At_ID, At_Description) VALUES(@At_ID,@At_Description)";<br/>
cmd = new SqlCommand(str, con);<br/>
cmd.Parameters.AddWithValue("@At_ID", TextBox_At_Name.Text);<br/>
cmd.Parameters.AddWithValue("@At_Description", TextBox_At_Desc.Text);<br/>
con.Open();<br/>
cmd.ExecuteNonQuery();<br/>
con.Close();<br/>
Response.Write("Record inserted");<br/>
<br/>
}<br/>
<br/>
protected void Button_FoI_Click(object sender, EventArgs e)<br/>
{<br/>
string str = "INSERT INTO fI(FI_ID, Description) VALUES(@FI_ID,@Description)";<br/>
cmd = new SqlCommand(str, con);<br/>
cmd.Parameters.AddWithValue("@FI_ID", TextBox_FoI_ID);<br/>
cmd.Parameters.AddWithValue("@Description", TextBox_FoI_Rationale);<br/>
con.Open();<br/>
cmd.ExecuteNonQuery();<br/>
con.Close();<br/>
Response.Write("Record inserted");<br/>
}<br/>
}<br/>
}


View the full article
 
Back
Top