My connection string is placed in web.config as follows.
<connectionStrings> <add name="empcon" connectionString="Persist Security Info=False;User ID=sa;Password=abc;Initial Catalog=db5pmto8pm;Data Source=SOWMYA-3BBF60D0\SOWMYA" /> </connectionStrings>
and program code ...
public partial class empoperations : System.Web.UI.Page { string constr = null; protected void Page_Load(object sender, EventArgs e) { ConfigurationManager.ConnectionStrings["empcon"].ToString(); if (!this.IsPostBack) { fillemps(); } } public void fillemps() { dlstemps.Items.Clear(); SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["empcon"].ConnectionString); con.ConnectionString = constr; SqlCommand cmd = new SqlCommand(); cmd.CommandText = "select * from emp"; cmd.Connection = con; SqlDataReader reader; try { con.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { ListItem lt = new ListItem(); lt.Text = reader["ename"].ToString(); lt.Value = reader["empno"].ToString(); dlstemps.Items.Add(lt); } reader.Close(); } catch (Exception er) { lblerror.Text = er.Message; } finally { con.Close(); }
I am completely new to programming ....
I can run this application with er.message in label management, because "the connection string property was not initialized"
I need to get a list of employee names from the emp table in the database from the drop-down list and show them to the user ...
can someone fix it ...
source share