Click here to Skip to main content
15,867,895 members
Articles / Web Development / HTML
Alternative
Tip/Trick

Load all the Country Names of the World in DropDown

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
7 May 2011CPOL 17.2K   2   9
Step1.Downlo...
Step1.
Download coma separated .CSV country file.
Step2.
Create new table for country
suppose CountryId,Country are their fields.

SQL
USE TestData
GO
CREATE TABLE Tbl_COUNTRY
( 
CountryId VARCHAR(40),
Country VARCHAR(40)
)
GO

Step3.
Now run following script to load all the data from CSV to database table
SQL
BULK
INSERT Tbl_COUNTRY
FROM 'c:\country_data.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO


Step4.
C#
protected void Page_Load(object sender, EventArgs e)
 {
        
        ddlLocation.DataSource = LoadCountryData() as DataTable;
        ddlLocation.DataTextField = "Country";
        ddlLocation.DataValueField = "CountryId";
        ddlLocation.DataBind();
 }


Download countrylist.csv
countrylist.txt[^]
coutrylist.csv[^]

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India



Hi I' Ambarish from India. I've three and half year of experience in application
development solutions.
Educational Qualification MCA -  from KristuJyoti College of management and technology (MG
University)

B.Sc (Physics) - from NSS College, Changanacherry (MG University)
Skill Set C#,winforms,asp.net,MVC 3, Java,Design Patterns,VB, Android,JQuery Mobile,SQL,MySqlUML.



Comments and Discussions

 
GeneralHi Anil. countrylist.csv file column has unsupported data fo... Pin
ambarishtv7-May-11 22:01
ambarishtv7-May-11 22:01 
GeneralWhen I run the following BULK INSERT Tbl_COUNTRY FROM 'C:\\c... Pin
Anil Srivastava7-May-11 10:16
Anil Srivastava7-May-11 10:16 
GeneralThank You Pin
ambarishtv3-May-11 4:01
ambarishtv3-May-11 4:01 
General5 for giving the link .. Now it became a complete solution. Pin
Prasanta_Prince3-May-11 4:00
Prasanta_Prince3-May-11 4:00 
GeneralReason for my vote of 5 Good solution after giving the CSV l... Pin
Prasanta_Prince3-May-11 3:59
Prasanta_Prince3-May-11 3:59 
Generalthank you for suggestion http://www.floresense.com/resc_cent... Pin
ambarishtv2-May-11 20:05
ambarishtv2-May-11 20:05 
GeneralRe: Hi Anil. countrylist.csv file column has unsupported data fo... Pin
ambarishtv7-May-11 22:00
ambarishtv7-May-11 22:00 
GeneralProvide the link to download CSV file. Pin
Prasanta_Prince1-May-11 6:09
Prasanta_Prince1-May-11 6:09 
GeneralRe: When I run the following BULK INSERT Tbl_COUNTRY FROM 'C:\... Pin
Anil Srivastava7-May-11 10:15
Anil Srivastava7-May-11 10:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.