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")); } } } }
Ramesh BarikPosted May 12, 2017, 3:43 AM
Ramesh BarikPosted May 12, 2017, 4:10 AM
Mohd lonpoPosted May 12, 2017, 4:02 AM