{"id":61,"date":"2018-07-06T16:22:00","date_gmt":"2018-07-06T14:22:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/2018\/07\/06\/how-to-generate-stored-procedure-automatically-from-visual-studio\/"},"modified":"2020-08-22T14:33:06","modified_gmt":"2020-08-22T12:33:06","slug":"how-to-generate-stored-procedure-automatically-from-visual-studio","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/how-to-generate-stored-procedure-automatically-from-visual-studio\/","title":{"rendered":"How to Generate Stored Procedure Automatically From Visual Studio"},"content":{"rendered":"<p>In this tutorial, I would explain to you how to generate stored automatically from Visual Studio without having to write codes.<\/p>\n<p>Let&#8217;s assume you have created the customer&#8217;s table in Microsoft SQL Server Managment Studio. This is shown in Figure 1.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/2.bp.blogspot.com\/-NxRaCXItink\/Wz-BpGwYCQI\/AAAAAAAACAc\/dzXJ2i40XtsV_yPsp80r6m7czvUAeXHdwCLcBGAs\/s1600\/How-to-Generate-Stored-Procedure-From-Visual.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/2.bp.blogspot.com\/-NxRaCXItink\/Wz-BpGwYCQI\/AAAAAAAACAc\/dzXJ2i40XtsV_yPsp80r6m7czvUAeXHdwCLcBGAs\/s640\/How-to-Generate-Stored-Procedure-From-Visual.jpg\" width=\"640\" height=\"432\" border=\"0\" data-original-height=\"635\" data-original-width=\"938\" \/>\u00a0<\/a><\/div>\n<div style=\"clear: both; text-align: center;\">Figure 1: Customer Table Definition in MS SQL Server<\/div>\n<p>&nbsp;<\/p>\n<p>You already know that it would not be easy to write the four stored procedure by writing it manually. So we are going to generate the following stored procedures:<\/p>\n<ul>\n<li>SelectCustomer<\/li>\n<li>UpdtateCustomer<\/li>\n<li>DeleteCustomer<\/li>\n<li>InsertCustomer<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Now\u00a0 let&#8217;s go to Visual Studio and start a new project. I have already done that. I am using Visual Studio 2015, but it woud also work with Visual Studio 2013 and 2017.<\/p>\n<ol>\n<li>Right-click on your project and click on you project in Solution Explore<\/li>\n<li>Click on Add New Item<\/li>\n<li>In the dialog box, Select Data on the left and Select DataSet from the list of items. This is shown in Figure 2<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/2.bp.blogspot.com\/-Fct0q3aMiF8\/Wz-HZkNCFYI\/AAAAAAAACAo\/YyU3KQKEpwMkAu6qL2OE_dDxLtBBJOoGQCLcBGAs\/s1600\/Choose%2BDataset.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/2.bp.blogspot.com\/-Fct0q3aMiF8\/Wz-HZkNCFYI\/AAAAAAAACAo\/YyU3KQKEpwMkAu6qL2OE_dDxLtBBJOoGQCLcBGAs\/s640\/Choose%2BDataset.jpg\" width=\"640\" height=\"387\" border=\"0\" data-original-height=\"580\" data-original-width=\"956\" \/>\u00a0<\/a><\/div>\n<div style=\"clear: both; text-align: center;\">Figure 2: Add a DataSet to the Project<\/div>\n<p>&nbsp;<\/p>\n<p>Give it a name and Click on Add ( i named it CustomerData). The DataSet designer opens as shown in Figure 4.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/4.bp.blogspot.com\/-SUsU4yV3NlE\/Wz-LL1HZ8LI\/AAAAAAAACA0\/HbuI-3QjTm8yCFxObJbXcGIDntfF1Qf0wCLcBGAs\/s1600\/Dataset-Designer.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/4.bp.blogspot.com\/-SUsU4yV3NlE\/Wz-LL1HZ8LI\/AAAAAAAACA0\/HbuI-3QjTm8yCFxObJbXcGIDntfF1Qf0wCLcBGAs\/s640\/Dataset-Designer.jpg\" width=\"640\" height=\"340\" border=\"0\" data-original-height=\"729\" data-original-width=\"1368\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<p>Right-click and select Add, the Select Table Adapter<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/4.bp.blogspot.com\/-n8ffJYzaazg\/Wz-LjmRkyZI\/AAAAAAAACA8\/gg9s6z-7GcY7lTG9zgobsfVnGOxiJEeuQCLcBGAs\/s1600\/Add%2BTable%2BAdapter.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/4.bp.blogspot.com\/-n8ffJYzaazg\/Wz-LjmRkyZI\/AAAAAAAACA8\/gg9s6z-7GcY7lTG9zgobsfVnGOxiJEeuQCLcBGAs\/s640\/Add%2BTable%2BAdapter.jpg\" width=\"640\" height=\"356\" border=\"0\" data-original-height=\"765\" data-original-width=\"1364\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<p>In the Database Connection window, Create a New database connection (or you can select from existing on if you have previously created one.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/4.bp.blogspot.com\/-kVTGdKcbVWs\/Wz-NB3TtEZI\/AAAAAAAACBI\/eQS5SeeLqrAqKfIKpj0-5_NYYxZyv8hqgCLcBGAs\/s1600\/Database%2BConnection.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/4.bp.blogspot.com\/-kVTGdKcbVWs\/Wz-NB3TtEZI\/AAAAAAAACBI\/eQS5SeeLqrAqKfIKpj0-5_NYYxZyv8hqgCLcBGAs\/s640\/Database%2BConnection.jpg\" width=\"640\" height=\"512\" border=\"0\" data-original-height=\"461\" data-original-width=\"575\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<p>Click on Next. Click on Next again<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/3.bp.blogspot.com\/-k-NmXOlp6CU\/Wz-PbtCSZdI\/AAAAAAAACBU\/r5P5JsmaCWkrgzw1oh9gQ1TFktuSjxdCgCLcBGAs\/s1600\/Choose%2BCreate%2BNew%2BStored%2BProcedure.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/3.bp.blogspot.com\/-k-NmXOlp6CU\/Wz-PbtCSZdI\/AAAAAAAACBU\/r5P5JsmaCWkrgzw1oh9gQ1TFktuSjxdCgCLcBGAs\/s640\/Choose%2BCreate%2BNew%2BStored%2BProcedure.jpg\" width=\"640\" height=\"512\" border=\"0\" data-original-height=\"461\" data-original-width=\"575\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<p>Choose Create new Stored Procedure and Click Next<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/4.bp.blogspot.com\/-eF9bUgbABAw\/Wz-Px08OmqI\/AAAAAAAACBc\/xGFgZ9AQeEMvLnwPQGalBJo1Uhv0o4oNwCLcBGAs\/s1600\/Enter%2Bthe%2BSelect%2BStatement.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/4.bp.blogspot.com\/-eF9bUgbABAw\/Wz-Px08OmqI\/AAAAAAAACBc\/xGFgZ9AQeEMvLnwPQGalBJo1Uhv0o4oNwCLcBGAs\/s640\/Enter%2Bthe%2BSelect%2BStatement.jpg\" width=\"640\" height=\"512\" border=\"0\" data-original-height=\"461\" data-original-width=\"575\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<p>In this window, you can either enter the statement (Select * From Customers) or you can use the Query Builder to select the table<\/p>\n<p><ins style=\"display: block; text-align: center;\" data-ad-client=\"ca-pub-7041870931346451\" data-ad-format=\"fluid\" data-ad-layout=\"in-article\" data-ad-slot=\"8227894917\"><\/ins><br \/>\nIf you click on Query Builder, you can select the Customers table and then click on the * for select all columns<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/1.bp.blogspot.com\/-4R1qfl5Cu0Y\/Wz-QhNyWnlI\/AAAAAAAACBo\/ZfsZUGXmtvQJE0H7pEVIIxE_-ZhQzDoKACLcBGAs\/s1600\/Use%2BQuery%2BBuilder%2Bto%2BSelect%2Ba%2BTable.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/1.bp.blogspot.com\/-4R1qfl5Cu0Y\/Wz-QhNyWnlI\/AAAAAAAACBo\/ZfsZUGXmtvQJE0H7pEVIIxE_-ZhQzDoKACLcBGAs\/s640\/Use%2BQuery%2BBuilder%2Bto%2BSelect%2Ba%2BTable.jpg\" width=\"640\" height=\"362\" border=\"0\" data-original-height=\"771\" data-original-width=\"1357\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<p>After you close the Query Builder, you should have your Select Statement written out for you.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/3.bp.blogspot.com\/-HraBHSUVL6A\/Wz-RO6Lr1VI\/AAAAAAAACBw\/KanQZceXB0M-2GKUwd5bwLitMaawdPBWACLcBGAs\/s1600\/Select%2BStatement%2BWritten%2Bfor%2BYou.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/3.bp.blogspot.com\/-HraBHSUVL6A\/Wz-RO6Lr1VI\/AAAAAAAACBw\/KanQZceXB0M-2GKUwd5bwLitMaawdPBWACLcBGAs\/s640\/Select%2BStatement%2BWritten%2Bfor%2BYou.jpg\" width=\"640\" height=\"512\" border=\"0\" data-original-height=\"461\" data-original-width=\"575\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<p>Click on Next<br \/>\nThe next window gives you\u00a0 option to name your stored procedures<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/1.bp.blogspot.com\/-2AcfMmDw2n4\/Wz-Rpo7kK3I\/AAAAAAAACB4\/s3xctdTfdOoB_BbruaQvzwixwDiAoAVzQCLcBGAs\/s1600\/You%2Bcan%2BEnter%2Bthe%2BNames%2Bof%2Bthe%2BStored%2BProcedure.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/1.bp.blogspot.com\/-2AcfMmDw2n4\/Wz-Rpo7kK3I\/AAAAAAAACB4\/s3xctdTfdOoB_BbruaQvzwixwDiAoAVzQCLcBGAs\/s640\/You%2Bcan%2BEnter%2Bthe%2BNames%2Bof%2Bthe%2BStored%2BProcedure.jpg\" width=\"640\" height=\"512\" border=\"0\" data-original-height=\"461\" data-original-width=\"575\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><b>About Naming Stored Procedures<\/b><\/p>\n<p>Use SelectCustomers, InsertCustomer, UpdateCustomer and DeleteCustomer. Note that the select statement uses the plural for the tablename while others uses singular<br \/>\nThis is because, the select statements selects multiple records at a time which other procedures executes on a single record at a time.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/3.bp.blogspot.com\/-IpVD-p3g7Mk\/Wz-SV1Nj5eI\/AAAAAAAACCE\/_YrIEll09iAe3xra4dK0EG3c30aez9XWQCLcBGAs\/s1600\/Stored%2BProcedure%2BNamed.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/3.bp.blogspot.com\/-IpVD-p3g7Mk\/Wz-SV1Nj5eI\/AAAAAAAACCE\/_YrIEll09iAe3xra4dK0EG3c30aez9XWQCLcBGAs\/s640\/Stored%2BProcedure%2BNamed.jpg\" width=\"640\" height=\"512\" border=\"0\" data-original-height=\"461\" data-original-width=\"575\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<p>Click on Next<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/3.bp.blogspot.com\/-6U4FtA-kqkw\/Wz-SsMVBXBI\/AAAAAAAACCM\/jyNktpyV8ZoidrfKVgVQX4J1qUN16lqegCLcBGAs\/s1600\/Uncheck%2Bthe%2Blast%2BCheckbox.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/3.bp.blogspot.com\/-6U4FtA-kqkw\/Wz-SsMVBXBI\/AAAAAAAACCM\/jyNktpyV8ZoidrfKVgVQX4J1qUN16lqegCLcBGAs\/s640\/Uncheck%2Bthe%2Blast%2BCheckbox.jpg\" width=\"640\" height=\"512\" border=\"0\" data-original-height=\"461\" data-original-width=\"575\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<p>Make sure to uncheck the last checkbox that says: &#8216;Create methods to send updates directly to the database&#8217;<\/p>\n<p>Click on Next to generate the stored procedures<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/1.bp.blogspot.com\/-aFmyykNPk-w\/Wz-TDrnCWXI\/AAAAAAAACCU\/4cnLMgD9VVsZsMqM_fHc6pnGYcY5DE7bACLcBGAs\/s1600\/Click%2Bon%2BFinis.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/1.bp.blogspot.com\/-aFmyykNPk-w\/Wz-TDrnCWXI\/AAAAAAAACCU\/4cnLMgD9VVsZsMqM_fHc6pnGYcY5DE7bACLcBGAs\/s640\/Click%2Bon%2BFinis.jpg\" width=\"640\" height=\"512\" border=\"0\" data-original-height=\"461\" data-original-width=\"575\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<p>If you have gotten to this point, then all the four store procedure has been generated in the SQL database.<br \/>\nClick on Finish to go back to the Dataset designer window<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/3.bp.blogspot.com\/-owIeMyOh5LE\/Wz-Tq48U95I\/AAAAAAAACCc\/oNxxMF_IyIkq_fFsZmfWMkZJyoHKL8qUwCLcBGAs\/s1600\/Back%2Bto%2BDataset%2BDesigner.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/3.bp.blogspot.com\/-owIeMyOh5LE\/Wz-Tq48U95I\/AAAAAAAACCc\/oNxxMF_IyIkq_fFsZmfWMkZJyoHKL8qUwCLcBGAs\/s640\/Back%2Bto%2BDataset%2BDesigner.jpg\" width=\"640\" height=\"340\" border=\"0\" data-original-height=\"728\" data-original-width=\"1366\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<p>Now, let&#8217;s head back to SQL Server Managment Studio to check is the Stored Procudures have been generated.<br \/>\nIf you expand the databases &gt; Programability &gt; Stored Procedures, you will see that the four procedures have been created successfully.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/1.bp.blogspot.com\/-2g3RdKhQzGQ\/Wz-UsD1On6I\/AAAAAAAACCo\/4-_TKWMsq4Y0SYQB6pm7G3p78B4JoUeEACLcBGAs\/s1600\/Check%2Bif%2BStored%2BProcedure%2Bhave%2Bbeen%2Bgenerated.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/1.bp.blogspot.com\/-2g3RdKhQzGQ\/Wz-UsD1On6I\/AAAAAAAACCo\/4-_TKWMsq4Y0SYQB6pm7G3p78B4JoUeEACLcBGAs\/s640\/Check%2Bif%2BStored%2BProcedure%2Bhave%2Bbeen%2Bgenerated.jpg\" width=\"640\" height=\"432\" border=\"0\" data-original-height=\"635\" data-original-width=\"938\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<p>So this is how to generate all your stored procdures from Visual Studio withou writing a single line of code! Isn&#8217;t ist amazing!<\/p>\n<p>Do leave a comment if you have any challenges following this tutorial<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, I would explain to you how to generate stored automatically from Visual Studio without having to write codes. Let&#8217;s assume you have &hellip; <\/p>\n","protected":false},"author":2,"featured_media":535,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[414,583],"tags":[],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/61"}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=61"}],"version-history":[{"count":2,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/61\/revisions"}],"predecessor-version":[{"id":537,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/61\/revisions\/537"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media\/535"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=61"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=61"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}