using sql server in c
TRANSCRIPT
![Page 1: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/1.jpg)
UniversityCollegeofSoutheastNorway
http://home.hit.no/~hansha
UsingSQLServerinC#withExamples
Hans-PetterHalvorsen,2016.11.01
<ThisDocumentisunderConstruction>
![Page 2: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/2.jpg)
2
TableofContents1. Introduction.......................................................................................................................4
2. SQLServer..........................................................................................................................5
2.1. DatabaseSystems.......................................................................................................5
2.2. StructuredQueryLanguage........................................................................................5
3. VisualStudio.......................................................................................................................6
3.1. The.NETFramework...................................................................................................6
3.2. TheC#Language.........................................................................................................6
4. DatabaseProgramminginC#.............................................................................................7
4.1. ADO.NET......................................................................................................................7
4.2. EnterpriseLibrary&DataAccessApplicationBlock....................................................8
4.3. LINQ.............................................................................................................................8
4.3.1. LINQtoSQL..........................................................................................................8
4.4. EntityFramework........................................................................................................8
4.4.1. LINQtoEntities.....................................................................................................8
5. ADO.NET...........................................................................................................................10
5.1. Introduction..............................................................................................................10
5.2. Examples...................................................................................................................10
6. EnterpriseLibrary.............................................................................................................11
6.1. DataAccessApplicationBlock...................................................................................11
6.1.1. Installation..........................................................................................................11
7. LINQ..................................................................................................................................13
![Page 3: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/3.jpg)
3 TableofContents
Tutorial:UsingSQLServerinC#-withExamples
7.1. LINQtoSQL...............................................................................................................13
8. EntityFramework.............................................................................................................14
8.1. …................................................................................................................................14
9. WebServices....................................................................................................................15
10. 3-TierArchitecure..........................................................................................................18
11. References.....................................................................................................................19
![Page 4: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/4.jpg)
4
1. IntroductionThisTutorialgivesanoverviewofdifferenttechniquesforcommunicationgwithSQLServerinVisualStudioandC#.
FormoreinformationaboutSoftwareandProgramming,pleaseseemywebsitelocatedhere:
http://home.hit.no/~hansha/
![Page 5: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/5.jpg)
5
2. SQLServer…
2.1. DatabaseSystems…
FormoreinformationaboutDatabaseSystems,pleaseseetheTutorial“IntroductiontoDatabaseSystems”locatedhere:
http://home.hit.no/~hansha/?tutorial=database
2.2. StructuredQueryLanguage…
FormoreinformationaboutSQL,pleaseseetheTutorial“StructuredQueryLanguage”locatedhere:
http://home.hit.no/~hansha/?tutorial=sql
![Page 6: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/6.jpg)
6
3. VisualStudioMicrosoftVisualStudioisanintegrateddevelopmentenvironment(IDE)fromMicrosoft.
HomepageofVisualStudio:http://www.visualstudio.com
FormoreinformationaboutVisualStudioandC#,pleaseseetheTutorial“IntroductiontoVisualStudioandC#”locatedhere:
http://home.hit.no/~hansha/?tutorial=csharp
3.1. The.NETFrameworkThe.NETFramework(pronounced“dotnet”)isasoftwareframeworkthatrunsprimarilyonMicrosoftWindows.ItincludesalargelibraryandsupportsseveralprogramminglanguagessuchasC#..NETisincludedwithVisualStudio.
3.2. TheC#LanguageC#ispronounced“seesharp”.C#isanobject-orientedprogramminglanguageandpartofthe.NETfamilyfromMicrosoft.C#isverysimilartoC++andJava.C#isdevelopedbyMicrosoftandworksonlyontheWindowsplatform.
![Page 7: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/7.jpg)
7
4. DatabaseProgramminginC#
VisualStudio,.NETandC#offerslotsofdifferenttechniquesforcommunicationgwithDatabases,espessiallySQLServer.
Someofthetechniquesdiscussedinthisdocumentare:
• ADO.NET• EnterpriseLibrary&DataAccessApplicationBlock• LINQ
o LINQtoSQLo LINQtoEnitities
• EntityFramework
4.1. ADO.NETADO.NETisthebasicdata-accesstechnologyfor.NET.
ADO.NET(ActiveXDataObjectfor.NET)isasetofcomputersoftwarecomponentsthatprogrammerscanusetoaccessdataanddataservices.ItisapartofthebaseclasslibrarythatisincludedwiththeMicrosoft.NETFramework.Itiscommonlyusedbyprogrammerstoaccessandmodifydatastoredinrelationaldatabasesystems,thoughitcanalsoaccessdatainnon-relationalsources.
http://msdn.microsoft.com/en-us/library/e80y5yhx(v=vs.110).aspx
ADO.NETprovidesconsistentaccesstodatasourcessuchasSQLServerandXML,andtodatasourcesexposedthroughOLEDBandODBC.
TheADO.NETclassesarefoundinSystem.Data.dll.
ADO.NETCodeExamples:http://msdn.microsoft.com/en-us/library/dw70f090(v=vs.110).aspx
![Page 8: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/8.jpg)
8 Error!Referencesourcenotfound.
Tutorial:UsingSQLServerinC#-withExamples
4.2. EnterpriseLibrary&DataAccessApplicationBlock
MicrosoftEnterpriseLibraryisacollectionofdifferentlibrariesthatmakesyourlifeasaprogrammereasier.InthisdocumentwewillonlyusetheDataAccessApplicationBlock.
TheDataAccessApplicationBlocksimplifiesmanycommondataaccesstaskssuchasreadingdatafordisplay,passingdatathroughapplicationlayers,andsubmittingchangeddatabacktothedatabasesystem.Itincludessupportforbothstoredproceduresandin-lineSQL,canexposethedataasasequenceofobjectsforclient-sidequerying,andprovidesaccesstothemostfrequentlyusedfeaturesofADO.NETinsimple-to-useclasses.
YoucanusetheNuGetPackageManagerinVisualStudiotoinstalltheEnterpriseLibraryassembliesthatyouneedinyourprojects.
DataAccessApplicationBlockWebSite:
http://msdn.microsoft.com/en-us/library/dn440726(v=pandp.60).aspx
4.3. LINQ…
4.3.1. LINQtoSQL
LINQtoSQLisamethodtoworkwithMicrosoftSQLServerdatabasesusingLINQ.
MicrosoftrecommendsthatyouuseEntityFrameworkfornewapplications,becauseLINQtoSQLwillnotbefurtherdeveloped.
4.4. EntityFramework…
EntityFrameworkOverview:http://msdn.microsoft.com/en-us/library/bb399567(v=vs.110).aspx
4.4.1. LINQtoEntities
![Page 9: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/9.jpg)
9 Error!Referencesourcenotfound.
Tutorial:UsingSQLServerinC#-withExamples
…
![Page 10: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/10.jpg)
10
5. ADO.NET…
5.1. Introduction…
5.2. Examples…
![Page 11: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/11.jpg)
11
6. EnterpriseLibraryEnterpriseLibraryispartofMicrosoftPatters&Practices.MicrosoftPatters&PracticesarerecommendationsonhowtodesignanddevelopcustomapplicationsusingtheMicrosoftplatform.
MicrosoftPatters&PracticesWebSite:http://msdn.microsoft.com/en-us/library/ff921345.aspx
EnterpriseLibraryWebSite:http://msdn.microsoft.com/en-us/library/ff648951.aspx
MicrosoftEnterpriseLibraryisacollectionofdifferentlibrariesthatmakesyourlifeasaprogrammereasier.InthisdocumentwewillonlyusetheDataAccessApplicationBlock.
6.1. DataAccessApplicationBlockTheDataAccessApplicationBlocksimplifiesmanycommondataaccesstaskssuchasreadingdatafordisplay,passingdatathroughapplicationlayers,andsubmittingchangeddatabacktothedatabasesystem.Itincludessupportforbothstoredproceduresandin-lineSQL,canexposethedataasasequenceofobjectsforclient-sidequerying,andprovidesaccesstothemostfrequentlyusedfeaturesofADO.NETinsimple-to-useclasses.
6.1.1. Installation
YoucanusetheNuGetPackageManagerinVisualStudiotoinstalltheEnterpriseLibraryassembliesthatyouneedinyourprojects.
InstallationoftheTheDataAccessApplicationBlock:
![Page 12: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/12.jpg)
12 Error!Referencesourcenotfound.
Tutorial:UsingSQLServerinC#-withExamples
![Page 13: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/13.jpg)
13
7. LINQ…
7.1. LINQtoSQL…
![Page 14: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/14.jpg)
14
8. EntityFramework…
8.1. ……
![Page 15: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/15.jpg)
15
9. WebServicesInmanysituationsourappsdon’tnecessarlyhavedirectaccesstothedatbase,especiallywhenyoursofwareisusedoursidethelocalcompanynetwork.InthesesituationsweneedtouseaWebServiceinordertowriteorreaddatafromthedatabase.
TodayWebServiceshavebeenverypopular.AWebserviceisamethodofcommunicationsbetweentwodevicesovertheWorldWideWeb,andmakesiteasytosharedataoveranetworkortheinternet.
AWebServiceis
• AWebAPI• AStandarddefinedbyW3C• Cross-platformandPlatform-independentCommunication• DistributedApplicationDevelopment
WebServicescanbeimplementedandusedinmostProgrammingLanguages(C#/ASP.NET,PHP,LabVIEW,Objective-C,Java,etc.)
![Page 16: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/16.jpg)
16 Error!Referencesourcenotfound.
Tutorial:UsingSQLServerinC#-withExamples
WebServicesusesstandardWebtechnology(Webprotocols)suchasHTTP,REST,SOAP,XML,WSDL,JSON,etc.
WebServicestechnologyusedinWebServices:
• HTTP-HypertextTransferProtocol
• XML–ExtensibleMarkupLanguage
• WSDL-WebServicesDescriptionLanguage
• SOAP-SimpleObjectAccessProtocol
![Page 17: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/17.jpg)
17 Error!Referencesourcenotfound.
Tutorial:UsingSQLServerinC#-withExamples
![Page 18: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/18.jpg)
18
10. 3-TierArchitecure…
![Page 19: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/19.jpg)
19
11. References….
![Page 20: Using SQL Server in C](https://reader031.vdocument.in/reader031/viewer/2022022416/5866e2561a28ab3b408b8e76/html5/thumbnails/20.jpg)
Hans-PetterHalvorsen,M.Sc.
E-mail:[email protected]
Blog:http://home.hit.no/~hansha/
UniversityCollegeofSoutheastNorway
www.usn.no