/////////////////////
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindContrydropdown();
}
}
///
/// Bind COuntrydropdown
///
protected void BindContrydropdown()
{
//conenction path for database
using (SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB"))
{
con.Open();
SqlCommand cmd = new SqlCommand("Select UserId,UserName FROM UserInformation", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
ddlCountry.DataSource = ds;
ddlCountry.DataTextField = "UserName";
ddlCountry.DataValueField = "UserId";
ddlCountry.DataBind();
ddlCountry.Items.Insert(0, new ListItem("--Select--", "0"));
con.Close();
}
}

Kunal VaishyaRank #990 · 2K reputationPosted Jul 17, 2013, 1:09 AM EDT
Kunal VaishyaRank #990 · 2K reputationPosted Jul 16, 2013, 8:21 PM EDT
Kunal VaishyaRank #990 · 2K reputationPosted Jul 16, 2013, 8:25 PM EDT
Try this code its working
IsraelRank #1,223 · 1.5K reputationPosted Jul 17, 2013, 12:10 AM EDT
A) my database is in sqlexpress, the exact path: database name: mfwamba, the table name: Alunos
B) in this code when I write this line code in red that's work using (SqlConnection con = new SqlConnection("Data Source=localhost\sqlexpress;Integrated Security=true;Initial Catalog=Mfwamba"))
for the point B its show me between the simbol "\" with "sqlexpress", this symbol "~"
Its strange because its sound the right path. But why its showing me this simbol "~"
Then when I take out this line "localhost\sqlexpress" and put "localhost" its works but giving this error message:A network-related or instance-specific error (...). The server was not found (...)
C) the message its pointed on this line of code: con.Open()
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindContrydropdown();
}
}
///
/// Bind COuntrydropdown
///
protected void BindContrydropdown()
{
//conenction path for database
using (SqlConnection con = new SqlConnection("Data Source=localhost\sqlexpress;Integrated Security=true;Initial Catalog=Mfwamba"))
{
con.Open();
SqlCommand cmd = new SqlCommand("Select UserId,UserName FROM UserInformation", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
ddlCountry.DataSource = ds;
ddlCountry.DataTextField = "UserName";
ddlCountry.DataValueField = "UserId";
ddlCountry.DataBind();
ddlCountry.Items.Insert(0, new ListItem("--Select--", "0"));
con.Close();
}
}
Ravi ShekharRank #673 · 3.6K reputationPosted Jul 17, 2013, 1:37 AM EDT
IsraelRank #1,223 · 1.5K reputationPosted Jul 17, 2013, 1:44 AM EDT
I didnt sleep well during three days. Thanx very much!
Israel.