Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i have excel sheet there are list of countries. i want to add country data in sql server but at the time of storing data it check validation like country is already exist in database or not? then store into db.
Posted

It is not that difficult.. easy one...
1.go to "SQL Server Management studio"
2.Right click on ur database name and select "Tasks -> Import Data"
3.Now select "Microsoft Excel" as DataSource
4.In Excel file path browse and give ur excel file(input)
5.Select appropriate excel version and give "Next"
6.Now select Destination as "SQL Server Native Client 10.0"
7.Select appropriate Sever name, DB name, Authentication and give "Next".
8.Now select "Write a query to specify the data to Transfer"
9.Now give ur query
10.give 3 times "Next" and then "Finish"

Now u have successfully inserted data to a new table created. If u want to add data to already existing table, after step 9 i.e. after giving ur query, select destination from the destination column displayed in the next step. Usually it shows a new table name but u can select already existing tables from the drop down list....

For any clarifications reply to this,
Mark it if u find it useful.
 
Share this answer
 
A similar question that I answered not very long ago: How to import excel data to SQL database table[^]

Once you understand how to do this, you can easily validate the data before saving as well. You just have to loop through the collection and see if that country exists in the db or not. And the way you check whether it exists in db or not, is to do a select query for that name and see if any results are returned (pretty basic really).
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900