Sql query
i am binding country dropdownlist from database ,I want to display india as a first item using sql query
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 23, 2013, 5:35 AM EST
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Insert_data_confirmation
{
public partial class WebForm6 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList_country.Items.Add(new ListItem("--Select--", "0"));
country2();
country1();
}
}
void country1()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from tab1 where country_name!='india' ";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
DropDownList_country.Items.Add(reader["country_name"].ToString());
}
reader.Close();
con.Close();
}
void country2()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from tab1 where country_name='india' ";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
DropDownList_country.Items.Add(reader["country_name"].ToString());
}
reader.Close();
con.Close();
}
}
}