{"id":69886,"date":"2021-08-21T15:30:43","date_gmt":"2021-08-21T19:30:43","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/random-c-and-ms-sql-server-19\/"},"modified":"2025-05-11T20:18:22","modified_gmt":"2025-05-11T20:18:22","slug":"random-c-and-ms-sql-server-19","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=69886","title":{"rendered":"Random C# and MS SQl Server #19"},"content":{"rendered":"<p>Foreign<strong> Key in Table Declaration<\/strong><\/p>\n<pre style=\"padding: 10px\">CREATE TABLE ORDERS (   ID integer primary key,    Order_Date datetime,    Customer_ID integer references CUSTOMER(ID),    Amount double); ALTER TABLE ORDERS ADD FOREIGN KEY (customer_id) REFERENCES CUSTOMER(ID);<\/pre>\n<p><strong>Stored Procedure Example<\/strong><\/p>\n<pre style=\"padding: 10px\">CREATE PROCEDURE [dbo].[procedure_name]      @param1 VARCHAR(100)     ,@param2 VARCHAR(200) OUTPUT    AS    \nBEGIN       \nDECLARE @param3 VARCHAR(100)       \nSET @param3 = ' '       \nIF @param1 IS NOT NULL AND LEN(@param1) &gt; 1            \nSELECT @param2 = 'The ' + @param1  + @param3        \nELSE             \nSELECT  @param2 = '...is cool!'        \nRETURN        \nEND    \nGO<\/pre>\n<p><strong>C# and Prepared Statements<\/strong><\/p>\n<pre style=\"padding: 20px\">int  id = 20;     \nstring  desc = \"....\" ;     \nSqlConnection rConn = new SqlConnection(\"Persist Security Info=False;Integrated Security=SSPI;        database=northwind;server=mySQLServer\");     \nrConn.Open();     \nSqlCommand command = new SqlCommand(null, rConn);     \n\n\/\/ Create and prepare an SQL statement.     \ncommand.CommandText = \"insert into Region (ID, Description) values (@id, @desc)\" ;     \ncommand.Parameters.Add ( \"@id\", id) ;     \ncommand.Parameters.Add ( \"@desc\", desc) ;     \ncommand.Prepare() ;  \n\n\/\/ Calling Prepare after having set the Commandtext and parameters.     command.ExecuteNonQuery(); \n    \n\/\/ Change parameter values and call ExecuteNonQuery.     command.Parameters[0].Value = 21;     \ncommand.Parameters[1].Value = \"mySecondRegion\";     command.ExecuteNonQuery();<\/pre>\n<pre style=\"padding: 20px\">conn = new SqlConnection(strConnectionString);   \nSqlCommand cmd = new SqlCommand();   \ncmd.CommandText =\"insert into Profile values(@Name,@Age)\";   \ncmd.Connection = conn;   \ncmd.CommandType = CommandType.Text;   \nSqlParameter nameP = new SqlParameter();   \nnameP.SqlDbType =SqlDbType.NVarChar;   \nnameP.ParameterName = \"@Name\";   \nnameP.Size = 50;   \nnameP.Value = model.Name;   \nSqlParameter ageP = new SqlParameter();   \nageP.SqlDbType =SqlDbType.Int;   \nageP.ParameterName = \"@Age\";   \nageP.Value = model.Age;   \ncmd.Parameters.Add(nameP);   \ncmd.Parameters.Add(ageP);   \nconn.Open();   \ncmd.Prepare();    \ncmd.ExecuteNonQuery();<\/pre>\n<p><strong>C# and Stored Procedure<\/strong><\/p>\n<pre style=\"padding: 10px\">conn = new SqlConnection(\"Server=(local);\nDataBase=Northwind;Integrated Security=SSPI\");       \nconn.Open();  \n     \nSqlCommand cmd  = new SqlCommand(\"sp_name\", conn);       \ncmd.CommandType = CommandType.StoredProcedure;       \ncmd.Parameters.Add(new SqlParameter(\"@CustomerID\", custId));     \n  \n\/\/ execute the command       \nrdr = cmd.ExecuteReader();     \n  \n\/\/ iterate through results, printing each to console       \nwhile (rdr.Read())       \n{          \nConsole.WriteLine(\"\" + rdr[\"Total\"] );       \n}<\/pre>\n<p>From: http:\/\/sitestree.com\/?p=5300<br \/> Categories:19<br \/>Tags:<br \/> Post Data:2007-02-11 12:57:35<\/p>\n<pre><code>    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\"&gt;https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    (Big Data, Cloud, Security, Machine Learning): Courses: &lt;a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"&gt; http:\/\/Training.SitesTree.com&lt;\/a&gt; \n    In Bengali: &lt;a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\"&gt;http:\/\/Bangla.SaLearningSchool.com&lt;\/a&gt;\n    &lt;a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\"&gt;http:\/\/SitesTree.com&lt;\/a&gt;\n    8112223 Canada Inc.\/JustEtc: &lt;a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\"&gt;http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) &lt;\/a&gt;\n    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com'&gt; https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    Medium: &lt;a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"&gt; https:\/\/medium.com\/@SayedAhmedCanada &lt;\/a&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Foreign Key in Table Declaration CREATE TABLE ORDERS ( ID integer primary key, Order_Date datetime, Customer_ID integer references CUSTOMER(ID), Amount double); ALTER TABLE ORDERS ADD FOREIGN KEY (customer_id) REFERENCES CUSTOMER(ID); Stored Procedure Example CREATE PROCEDURE [dbo].[procedure_name] @param1 VARCHAR(100) ,@param2 VARCHAR(200) OUTPUT AS BEGIN DECLARE @param3 VARCHAR(100) SET @param3 = &#8216; &#8216; IF @param1 IS NOT &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=69886\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1973,1917],"tags":[],"class_list":["post-69886","post","type-post","status-publish","format-standard","hentry","category-c-misc","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":70287,"url":"http:\/\/bangla.sitestree.com\/?p=70287","url_meta":{"origin":69886,"position":0},"title":"Random C# and MS SQl Server #.Net Web Applications","author":"Author-Check- Article-or-Video","date":"August 31, 2021","format":false,"excerpt":"Brought from: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=1321&title=Random%20C#%20and%20MS%20SQl%20Server Foreign Key in Table Declaration CREATE TABLE ORDERS ( ID integer primary key, Order_Date datetime, Customer_ID integer references CUSTOMER(ID), Amount double ); ALTER TABLE ORDERS ADD FOREIGN KEY (customer_id) REFERENCES CUSTOMER(ID); Stored Procedure Example CREATE PROCEDURE [dbo].[procedure_name] @param1 VARCHAR(100) ,@param2 VARCHAR(200) OUTPUT AS BEGIN DECLARE @param3 VARCHAR(100)\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10162,"url":"http:\/\/bangla.sitestree.com\/?p=10162","url_meta":{"origin":69886,"position":1},"title":"ThreeParams.java Servlet that reads and displays three request (form) parameters. Uses the ServletUtilities class.","author":"","date":"August 16, 2015","format":false,"excerpt":"ThreeParams.java\u00a0 Servlet that reads and displays three request (form) parameters. Uses the ServletUtilities\u00a0 class. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; \/** Simple servlet that reads three parameters from the \u00a0*\u00a0 form data. \u00a0* \u00a0 \u00a0*\u00a0 Taken from Core Web Programming Java 2 Edition \u00a0*\u00a0 from Prentice Hall and\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26527,"url":"http:\/\/bangla.sitestree.com\/?p=26527","url_meta":{"origin":69886,"position":2},"title":"ThreeParams.java  Servlet that reads and displays three request (form) parameters. Uses the ServletUtilities  class. #Programming Code Examples #Java\/J2EE\/J2ME #Servlet","author":"Author-Check- Article-or-Video","date":"April 27, 2021","format":false,"excerpt":"ThreeParams.java Servlet that reads and displays three request (form) parameters. Uses the ServletUtilities class. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; \/** Simple servlet that reads three parameters from the * form data. * * Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65654,"url":"http:\/\/bangla.sitestree.com\/?p=65654","url_meta":{"origin":69886,"position":3},"title":"XML Related Classes in .Net #Misc .Net","author":"Author-Check- Article-or-Video","date":"July 10, 2021","format":false,"excerpt":"Brought from our old site (yes, very old short-note): http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=633&title=XML%20Related%20Clasees%20in%20.Net XML in ADO.net VB.NET C#.NET XML is the foundation of .NET. .NET internally represents data as XML and hence can provide inter-operability and interaction among applications written in different platforms and languages [.Net compatible]. XmlReader In .Net you can use\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":69924,"url":"http:\/\/bangla.sitestree.com\/?p=69924","url_meta":{"origin":69886,"position":4},"title":"XML Related Clasees in .Net #18","author":"Author-Check- Article-or-Video","date":"August 22, 2021","format":false,"excerpt":"XML in ADO.net VB.NET C#.NETXML is the foundation of .NET. .NET internally represents data as XML and hence can provide interoperability and interaction among applications written in different platforms and languages[.Net compatible].XmlReader In .Net you can use XML with SqlCommand object. You first create a connection to the sql server\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":74657,"url":"http:\/\/bangla.sitestree.com\/?p=74657","url_meta":{"origin":69886,"position":5},"title":"Python and MySQL Operations. Code Examples","author":"Sayed","date":"May 17, 2022","format":false,"excerpt":"#!\/usr\/bin\/env python# coding: utf-8# In[1]: import mysql.connector # In[2]: # create a database connection # In[3]: import mysql.connectormydb = mysql.connector.connect(\u00a0 host=\"localhost\",\u00a0 user=\"root\",\u00a0 password=\"\")print(mydb) # In[4]: import mysql.connectormydb = mysql.connector.connect(\u00a0 host=\"localhost\",\u00a0 user=\"root\",\u00a0 password=\"\")mycursor = mydb.cursor()mycursor.execute(\"drop DATABASE mydatabase\");mycursor.execute(\"CREATE DATABASE mydatabase\"); # In[5]: # check if database exists # In[6]: import mysql.connectormydb =\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/bangla.sitestree.com\/?cat=1428"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/69886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=69886"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/69886\/revisions"}],"predecessor-version":[{"id":78129,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/69886\/revisions\/78129"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=69886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=69886"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=69886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}