/////////////////////
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 VaishyaPosted Jul 17, 2013, 5:09 AM
IsraelPosted Jul 17, 2013, 5:44 AM
I didnt sleep well during three days. Thanx very much!
Israel.
Ravi ShekharPosted Jul 17, 2013, 5:37 AM
IsraelPosted Jul 17, 2013, 4:10 AM
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();
}
}
Kunal VaishyaPosted Jul 17, 2013, 12:25 AM
Try this code its working
Kunal VaishyaPosted Jul 17, 2013, 12:21 AM