0

How to Import Excel into MS SQL database table.

Posted by Nantharupan on 1:00 PM in , ,
I was asked to import the data from the Excel to MSSQL database. I wasn't aware of how to do that. However i found the way to do that. I hope this would help some one. 

So Steps,

1. Save the sheet/file as .csv, (Save the file with the same name of the data table would make your life easy )
2. Make sure the column name matches with the data base column names. 
3. Right click on the data base  and select task and import
4. Choose a Data Source -- Choose the Flat File as Type and Particular File,
5. Choose a Destination -- Choose the Destination as SQL Native Client, 
6. Select the data base and Authentication 
7. Make sure all the columns are mapped correctly, 
8. Finish and see are there any errors, (keep in mind there can be data loses, so make sure the whole process fails or success on such occasion by setting the right fails)

Key Points to note

  • Make sure there are no data could loss
  • Make sure the right local
  • Make sure the right column mapping 

0

SQL Bulk Copy

Posted by Nantharupan on 1:00 PM in , ,
Some times we faced situation when we need to insert single row for each millions of iterations. For example, we read from an Excel file which contains millions of students records and we want to add the details to the data base.  This can be done using the Entity Framework as follows,

                foreach (var student in students)
                {
                        using (var ctx = new dbContext())
                        {
                            ctx.Students.AddObject(student);
                            ctx.SaveChanges();
                        }              
                }

However this is inefficient. We can make use of SqlBulkCopy class to do the trick.

          string connString = "";
            // connect to SQL
            using (SqlConnection connection =  new SqlConnection(connString))
            {
                // make sure to enable triggers
                // more on triggers in next post
                SqlBulkCopy bulkCopy = new SqlBulkCopy(
                    connection,
                    SqlBulkCopyOptions.TableLock |
                    SqlBulkCopyOptions.FireTriggers |
                    SqlBulkCopyOptions.UseInternalTransaction,
                    null
                    );

                // set the destination table name
                bulkCopy.DestinationTableName = "tableName";
                connection.Open();

                // write the data in the "dataTable"
                bulkCopy.WriteToServer(dataTable);
                connection.Close();
            }
This would help to reduce the over head.

Visual Studio 2015 - Some useful Short Cuts

Posted by Nantharupan on 12:00 PM in , ,
I have started to working in Visual Studio again after a some time. I have noticed there are some new and useful short cuts, which would make developers life easier. So i listed down some of them. 


  • Alt+Up/Down - Move the code up or down
  • Clt+M+H - Clt+M+U to create a collapsible region
  • Clt+K+C - Clt+K+U to create a comment or un comment
  • Alt F12 to peek a definition from the code
  • Shift + F12 to find all references
  • Clt + Shift + F find in all files
  • Clt + G to go to a particular line number
  • F12 go to definition
  • Ctl \ + E to error list
  • Ctl + F4 close the window
  • Ctl + M + X expand all outline
  • Ctl+M + A Collapse all outline
  • ctrl + k, ctrl + d – Format Document

Find all ports being used by processes - Command Line Commands

Posted by Nantharupan on 11:30 AM in ,
Recently i faced a problem, when i try to deploy one service in my windows pc, it was throwing an error that the port is being used by some other process. I had to find which is the program running in that port, and i finally found the following set's of commands are useful on finding the processes running in each port

Go to 
C:\Windows\System32 and run the following command to get 

To display both the Ethernet statistics and the statistics for all protocols, type the following command:
netstat -e -s
To display the statistics for only the TCP and UDP protocols, type the following command:
netstat -s -p tcp udp
To display active TCP connections and the process IDs every 5 seconds, type the following command:
nbtstat -o 5
To display active TCP connections and the process IDs using numerical form, type the following command:
nbtstat -n -o


Popular posts

Copyright © 2009 On the way All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive.