Mohd lonpo

Mohd lonpo

  • NA
  • 24
  • 2.4k

Saving data from one DB Table in DropDown to another DBTable

May 12 2017 3:20 AM
How can i save the data which we got from one table of database to another table. Actually i want first to get data from first table using DROPDOWN and then save the data (i.e.Employee ID and Employee name) which we got in dropdown to another table of the database.
HTML code:
<asp:DropDownList ID="ddlEmployees" runat="server" AutoPostBack="true" OnSelectedIndexChanged="OnSelectedIndexChanged_ddlEmployees">
</asp:DropDownList>
<br />

CS Code:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.PopulateDropDownList();
}
}
private void PopulateDropDownList()
{
string constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT FirstName,EmployeeID FROM Employees", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
this.ddlEmployees.DataTextField = "FirstName";
this.ddlEmployees.DataValueField = "EmployeeID";
this.ddlEmployees.DataSource = ds;
this.ddlEmployees.DataBind();
this.ddlEmployees.Items.Insert(0, new System.Web.UI.WebControls.ListItem(" --Select Please-- ", "0"));
}
}
}
}

Answers (3)