protected void ddlNoOfMonths_SelectedIndexChanged(object sender, EventArgs e) { ddlmonthlypay.Items.Clear(); ddlmonthlypay.AppendDataBoundItems = true; String strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString; String strQuery = "select ID, MonthlyPay from Tmonthlypay where NoOfMonthsID=@NoOfMonthsID"; SqlConnection con = new SqlConnection(strConnString); SqlCommand cmd = new SqlCommand(); cmd.Parameters.AddWithValue("@NoOfMonthsID", ddlNoOfMonths.SelectedItem.Value); cmd.CommandType = CommandType.Text; cmd.CommandText = strQuery; cmd.Connection = con; try { con.Open(); ddlmonthlypay.DataSource = cmd.ExecuteReader(); ddlmonthlypay.DataTextField = "MonthlyPay"; ddlmonthlypay.DataValueField = "ID"; ddlmonthlypay.DataBind(); if (ddlmonthlypay.Items.Count > 1) { ddlmonthlypay.Enabled = true; } else { ddlmonthlypay.Enabled = false; } } catch (Exception ex) { throw ex; } finally { con.Close(); con.Dispose(); } }
Hi, you just put below code into your try...catch box try { con.Opern(); SqlDataReader sqlRed = cmd.ExecuteReader(); while (sqlRed.Read()) { //replace your text box name with TextBox1 TextBox1.Text = Convert.ToString(sqlRed["MonthlyPay"]); } ......
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)