Beruflich Dokumente
Kultur Dokumente
College of Engineering
Dept. of MCA
MASTEROFCOMPUTERAPPLICATIONS
VSEMESTER
13MCA57
.NETLaboratory
COMPILEDBY
1.HarishM2.Sandeepapateel
R.V.College of Engineering
Dept. of MCA
CONTENTS
SL.
No.
Description
VTUListofprograms
Introductionto.Net
WriteaPrograminC#todemonstratecommandLineargument.
WriteaPrograminC#todemonstrateBoxingandunBoxing.
WriteaProgramtodemonstrateOperatoroverloading.
Findthesumofalltheelementspresentinajaggedarrayof3innerarrays.
UsingTry,CatchandFinallyblockswriteaprograminC#todemonstrate
errorhandling.
DemonstrateUseOfVirtualandoverridekeywordinC#withasimple.
Program.Writeaprogramtodemonstratedelegates.
10
11
12
WriteaprogramtodemonstrateabstractclassandabstractmethodsinC#.
WriteaprogramtoillustratetheuseofdifferentpropertiesinC#.
Demonstratearraysofinterfacetypes(forruntimepolymorphism)witha
C#program.WriteaPrograminC#todemonstratecommandLine
Page
No.
R.V.College of Engineering
Dept. of MCA
argument.
13
WriteaPrograminC#todemonstrateBoxingandunBoxing
14
WriteaProgramtodemonstrateOperatoroverloading.
PARTB
15
ConsidertheDatabaseSTUDENTconsistingoffollowingtables:tbl_Course
(CourseID:int,CourseName:string)tbl_Student(USN:string,StudName:
string,Address:string,CourseID:int,YrOfAdmsn:int)
DevelopsuitablewindowsapplicationusingC#.NEThavingfollowing
options:
1.Enteringnewcoursedetails.
2.Enteringnewstudentdetails.
3.Displaythedetailsofstudents(inaGrid)whobelongtoaparticular
course.
4.Displaythedetailsthestudentswhohavetakenadmissioninaparticular
year.
16
ConsidertheDatabaseSTUDENTconsistingoffollowingtables:
ConsidertheDatabaseBLOODBANKconsistingoffollowingtables:
tbl_BloodGroup(BloodID:int,BloodGroup:string)tbl_Donor(DonorID:
int,DonorName:stirng,Address:string,ContactNo:int,DOB:date,Gender:
string,Weight:int,BloodID:int)
DevelopsuitablewindowsapplicationusingC#.NEThavingfollowing
options:
1.EnteringBloodgroupdetails.
R.V.College of Engineering
Dept. of MCA
2.Enteringnewdonordetails.
3.Displaythedetailsofdonors(inaGrid)havingparticularbloodgroup.
4.Displaythedetailsofdonors(inaGrid)basedongender.
5.Displaythedetailsofdonors(inaGrid)basedonage(above18),weight
(above45KG)and
Gender(userschoice).
17
ConsidertheDatabaseSTUDENTconsistingoffollowingtables:tbl_Course
(CourseID:int,CourseName:string)tbl_Book(BookID:int,BookTitle:
string,Author:string,CourseID:int)tbl_Student(USN:string,StudName:
string,CourseID:int)tbl_BookIssue(USN:string,BookID:int,IssueDate:
Date)
DevelopsuitablewindowsapplicationusingC#.NEThavingfollowing
options:
1.NewCourseEntry.
2.NewBookEntry
3.NewStudentEntry
4.Issueofbookstoastudent.
5.Generatereport(displayinagrid)showingallthebooksbelongingto
particularcourse.
6.Generatereport(displayinagrid)showingallthebooksissuedona
particulardate.
7.Generatereport(displayinagrid)showingallthebooksissuedtoa
particularstudent.
18
DevelopaWebApplicationusingC#.NETandASP.NETforaneducational
institution.ThemasterpageshouldconsistofInstitutionName,LogoandAddress.
Also,itshouldprovidehyperlinkstoDepartments,FacilitiesAvailableand
Feedback.Eachdepartmentpageandfacilitiespageshouldbedesignedasstatic
pages.ThehyperlinksshouldnavigatetothesestaticpagesintheformofContent
R.V.College of Engineering
Dept. of MCA
PagesassociatedwithMasterPagedesigned.TheFeedbackpageshouldhavefields
toenterName,EmailandMessagewithSubmitandCancelButtons.Database
shouldbecreatedtostorethesethreedata.
19
DevelopaWebApplicationusingC#.NETandASP.NETforaBank.TheBANK
Databaseshouldconsistoffollowingtables:tbl_Bank(BankID:int,BankName:
string)tbl_Branch(BranchID:int,BankID:int,BranchName:string)tbl_Account
(AccountNo:int,BankID:int,BranchID:int,CustomerName:string,Address:
string,ContactNo:int,Balance:real)(Note:AccountNoandBankIDtogetherisa
compositeprimarykey).
ThemasterpageofthiswebapplicationshouldcontainhyperlinkstoNewBank
Entry,NewBranchEntry(ofselectedBank),NewCustomerEntry(basedon
branchandbank)andReportGeneration.Thehyperlinksshouldnavigateto
respectivecontentpages.Thesecontentpagesprovidethefieldsforrespectivedata
entry.Thereportsshouldbegenerated(displayingrid)asbelow:
1.Displayallrecordsofparticularbank.
2.Displayallrecordsofabranchofparticularbank.
3.Thebalanceshouldbedisplayedfortheenteredaccountnumber(Bankand
Branch
areinputthroughComboBoxcontrolsandAccountnumberisinputthrough
TextBox).
R.V.College of Engineering
Dept. of MCA
Nos
Programnumberwiththequestion
PartA
1
WriteaPrograminC#todemonstratecommandLineargument.
WriteaPrograminC#todemonstrateBoxingandunBoxing
WriteaProgramtodemonstrateOperatoroverloading.
Findthesumofalltheelementspresentinajaggedarrayof3innerarrays.
UsingTry,CatchandFinallyblockswriteaprograminC#todemonstrateerror
handling.
DemonstrateUseOfVirtualandoverridekeywordinC#withasimpleProgram.
Writeaprogramtodemonstratedelegates.
WriteaprogramtodemonstrateabstractclassandabstractmethodsinC#.
WriteaprogramtoillustratetheuseofdifferentpropertiesinC#
10
Demonstratearraysofinterfacetypes(forruntimepolymorphism)withaC#
program.
PartB
ConsidertheDatabaseSTUDENTconsistingoffollowingtables:tbl_Course
(CourseID:int,CourseName:string)tbl_Student(USN:string,StudName:string,
Address:string,CourseID:int,YrOfAdmsn:int)
DevelopsuitablewindowsapplicationusingC#.NEThavingfollowingoptions:
1.Enteringnewcoursedetails.
2.Enteringnewstudentdetails.
3.Displaythedetailsofstudents(inaGrid)whobelongtoaparticularcourse.
R.V.College of Engineering
Dept. of MCA
4.Displaythedetailsthestudentswhohavetakenadmissioninaparticularyear.
ConsidertheDatabaseSTUDENTconsistingoffollowingtables:
ConsidertheDatabaseBLOODBANKconsistingoffollowingtables:
tbl_BloodGroup(BloodID:int,BloodGroup:string)tbl_Donor(DonorID:int,
DonorName:stirng,Address:string,ContactNo:int,DOB:date,Gender:string,
Weight:int,BloodID:int)
DevelopsuitablewindowsapplicationusingC#.NEThavingfollowingoptions:
1.EnteringBloodgroupdetails.
2.Enteringnewdonordetails.
3.Displaythedetailsofdonors(inaGrid)havingparticularbloodgroup.
4.Displaythedetailsofdonors(inaGrid)basedongender.
5.Displaythedetailsofdonors(inaGrid)basedonage(above18),weight
(above45KG)and
Gender(userschoice).
ConsidertheDatabaseSTUDENTconsistingoffollowingtables:tbl_Course
(CourseID:int,CourseName:string)tbl_Book(BookID:int,BookTitle:string,
Author:string,CourseID:int)tbl_Student(USN:string,StudName:string,
CourseID:int)tbl_BookIssue(USN:string,BookID:int,IssueDate:Date)
DevelopsuitablewindowsapplicationusingC#.NEThavingfollowingoptions:
1.NewCourseEntry.
2.NewBookEntry
3.NewStudentEntry
4.Issueofbookstoastudent.
5.Generatereport(displayinagrid)showingallthebooksbelongingto
R.V.College of Engineering
Dept. of MCA
particularcourse.
6.Generatereport(displayinagrid)showingallthebooksissuedonaparticular
date.
7.Generatereport(displayinagrid)showingallthebooksissuedtoaparticular
student.
4
DevelopaWebApplicationusingC#.NETandASP.NETforaneducationalinstitution.
ThemasterpageshouldconsistofInstitutionName,LogoandAddress.Also,itshould
providehyperlinkstoDepartments,FacilitiesAvailableandFeedback.Eachdepartment
pageandfacilitiespageshouldbedesignedasstaticpages.Thehyperlinksshould
navigatetothesestaticpagesintheformofContentPagesassociatedwithMasterPage
designed.TheFeedbackpageshouldhavefieldstoenterName,EmailandMessagewith
SubmitandCancelButtons.Databaseshouldbecreatedtostorethesethreedata.
DevelopaWebApplicationusingC#.NETandASP.NETforaBank.TheBANKDatabase
shouldconsistoffollowingtables:tbl_Bank(BankID:int,BankName:string)tbl_Branch
(BranchID:int,BankID:int,BranchName:string)tbl_Account(AccountNo:int,BankID:
int,BranchID:int,CustomerName:string,Address:string,ContactNo:int,Balance:real)
(Note:AccountNoandBankIDtogetherisacompositeprimarykey).
ThemasterpageofthiswebapplicationshouldcontainhyperlinkstoNewBankEntry,
NewBranchEntry(ofselectedBank),NewCustomerEntry(basedonbranchandbank)
andReportGeneration.Thehyperlinksshouldnavigatetorespectivecontentpages.
Thesecontentpagesprovidethefieldsforrespectivedataentry.Thereportsshouldbe
generated(displayingrid)asbelow:
1.Displayallrecordsofparticularbank.
2.Displayallrecordsofabranchofparticularbank.
3.Thebalanceshouldbedisplayedfortheenteredaccountnumber(BankandBranch
areinputthroughComboBoxcontrolsandAccountnumberisinputthroughTextBox).
R.V.College of Engineering
Dept. of MCA
IntroductiontoDotNet
.Netisaframework,whichisacollectionoftools,technologies,andlanguagesallthese
worktogetherinaframeworktoprovidethesolutionsthatareneededtoeasilybuild
anddeploytrulyrobustenterpriseapplications.Itisnotaoperatingsystemnora
programminglanguage.ItsalayerbetweentheOSandtheprogramminglanguage.It
consistofCLR(CommonLanguageRuntime),CTS(CommontypeSystem)andCLS
(CommonLanguageSpecification).
.NetsupportsmanyprogramminglanguageslikeVB.NET,C#etc.Itprovidescommon
setofclasslibrariesto.netbasedprogramminglanguages.
HereprogramsareexecutedusingC#(pronounced"Csharp")programminglanguage.
C#isalmostsameasJava.Nopointersrequired.Itmanagesthememoryautomatically.
Supportsoperatoroverloadingandinterfacebasedprogrammingtechniques.C#can
producecodethatcanrunonlyon.NETenvironment.
VisualC#.NETisMicrosoft'sC#developmenttool.Itincludesaninteractive
developmentenvironment,visualdesignersforbuildingWindowsandWebapplications,
acompiler,andadebugger.VisualC#.NETispartofasuiteofproducts,calledVisual
Studio.NET,thatalsoincludesVisualBasic.NET,VisualC++.NET,andtheJScript
scriptinglanguage.
Namespacesarethewaytoorganize.NETFrameworkClassLibraryintoalogical
groupingaccordingtotheirfunctionality,usabilityaswellascategorytheyshould
belongto.Namespacesarelogicalgroupingoftypesforthepurposeofidentification.
TheSystemNamespacesistherootfortypesinthe.NETFramework.
In.NetlanguageseveryprogramiscreatedwithadefaultNamespaces.Programmerscan
alsocreatetheirownNamespacesin.Netlanguages
R.V.College of Engineering
Dept. of MCA
1.InC#programmingtheclassneednotbesameasthefilename.HereisabasicC#
program:
usingSystem;ImportingaNamespace
//ThisprogramillustratesC#basicsyntaxComments
publicclassSimpleProgramClassWrapper
{
staticvoidMain()syntaxMainmethod
{
}
Console.WriteLine("Hello");
}
UsingisaC#keyword,whichisareservedword,whichhavespecialmeaningaina
languageandthereforecannotbeusedbyprogrammersasthenamesofvariable,
functionsoranyoftheotherC#buildingblocks
AnamespaceisalogicalgroupingofpredefinedC#programmingelement.using
System;statementisrequiredtocompileandruntheprogramproperly.
//tocommentjusttotheendoflinei.e.singlelinecomment
/*thisisamultilineorblockcomment*/
ClassWrapperAclassdeclarationinC#iscomposedofattributes,modifiers,the
classnameandabody.Thebodycontainsclassmembersthatcanincludeconstants,
variables,methods,properties,events,operators.
MainMethoditservesastheentrypointforaC#program.Whentheprogram
executableisinvoked,thesystemwillcalltheMainmethodtolaunchtheapplication.
10
R.V.College of Engineering
Dept. of MCA
Solutions
11
R.V.College of Engineering
Dept. of MCA
1.WriteaPrograminC#todemonstrateCommandlineargumentsprocessing.
BasicallymainmethodcanhavetwoSignatures.
staticvoidMain(string[]args)
or
staticintMain(string[]args)
Inwhichstring[]argswillstorewhateverispassedthroughcommandlinetothe
application.WecanprocessalltheelementspassedintocommandLinebysimplyprocessingthearray
string[]args.TheparameteroftheMainmethodisastringarraythatrepresentsthe
commandlinearguments.Tocheckfortheexistenceoftheargumentscan,itbedoneby
testingthelengthproperty.
WecanaccessCommandLineArgumentsgloballyUsingEnvironmentClass's
GetCommandLineArguments()methodwhichreturnsstring[]arrayofallCommandLineArguments.So
onecanusecommandlineargumentspassedtoMainfunctionanywereinProgramwithoutpassingitany
were.
Program:
usingSystem;
classcmdarg
{
publicstaticvoidMain(String[]args)
{
intnum=0;
for(inti=0;i<args.Length;i++)
num=num+int.Parse(argst[i]);
Console.WriteLine("Sumofthegivencommandlineargumentsis:"+
num);
}
}
Commandlinearguments(12345)arefedinthepropertiesoftheprogram.
TestData:
Clickon'Run>Runwith>CustomParameters>Enter12345
Sumofthegivencommandlineargumentsis:15
12
R.V.College of Engineering
Dept. of MCA
2.WriteaPrograminC#todemonstrateboxingandunBoxing.
Boxing
Itisdefinedastheprocessofexplicitlyconvertingavaluetypeintoacorresponding
referencetypebystoringthevariableinaSystem.Object.
Consideranexampleavariableoftypeshort:
shorts=25;
If,duringthecourseofyourapplication,youwishtorepresentthisvaluetypeasa
referencetype,youwouldboxthevalueasfollows:
//Boxthevalueintoanobjectreference.
objectobjShort=s;
Whenyouboxavalue,theCLRallocatesanewobjectontheheapandcopiesthevalue
typesvalue(inthiscase,25)intothatinstance.Whatisreturnedtoyouisareferenceto
thenewlyallocatedobject.
1.UnBoxing
Itistheprocessofconvertingthevalueheldintheobjectreferencebackintoa
correspondingvaluetypeonthestack.Theunboxingoperationbeginsbyverifyingthat
thereceivingdatatypeisequivalenttotheboxedtype,andifso,itcopiesthevalueback
intoalocalstackbasedvariable.
Thefollowingunboxingoperationworkssuccessfully,giventhattheunderlyingtypeof
theobjShortisindeedashort.
//Unboxthereferencebackintoacorrespondingshort.
shortanotherShort=(short)objShort;
Program:
usingSystem;
classProgram
{
staticvoidMain(String[]args)
{
Objecto;
Console.WriteLine(Readingintegervalueintanobject(boxing));
Console.WriteLine(Enteranintegervalue:);
o=int.Parse(Console.ReadLine());
inti=(int)o;
13
R.V.College of Engineering
Console.WriteLine(Boxedvalue:o=+o);
Console.WriteLine(Unboxingvalueofobjectintointegeri:i=+i);
Dept. of MCA
Console.WriteLine(Readingstringintoanobject(boxing));
Console.WriteLine(Enterastring:);
o=Console.ReadLine();
stringstr=(String)o;
Console.WriteLine(Boxedvalue:o=+o);
Console.WriteLine(Unboxingvalueofobjectintointegerstr:str=+str);
TestData:
Readingintegervalueintanobject(boxing)
Enteranintegervalue:1234
Boxedvalue:o=1234
Unboxingvalueofobjectintointegeri:i=1234
Readingstringintoanobject(boxing)
Enterastring:Hello
Unboxingvalueofobjectintointegerstr:str=Hello
3.WriteaprogramtodemonstrateOperatoroverloading.
Operatoroverloading,alsoknownasoverloading,providesawaytodefineanduse
operatorssuchas+,,and/foruserdefinedclassesorstructs.Itallowsusto
define/redefinethewayoperatorsworkwithourclassesandstructs.Thisallows
programmerstomaketheircustomtypeslookandfeellikesimpletypessuchasintand
string.Itconsistsofnothingmorethanamethoddeclaredbythekeywordoperatorand
followedbyanoperator.Therearethreetypesofoverloadableoperatorscalledunary,
binary,andconversion.Notalloperatorsofeachtypecanbeoverloaded.
OverloadingUnaryOperators:
Theyinclude+,,!,~,++,,true,andfalse.
OverloadingBinaryOperator:Binaryoperatorsarethosethatrequiretwo
operands/parametersfortheoperation.Oneoftheparametershastobeofatypein
whichtheoperatorisdeclared.Theyinclude
+,,*,/,%,&,|,^,<<,>>,==,!=,>,<,>=,and<=.
OverloadingConversionOperator:Conversionoperatorsarethosethatinvolve
convertingfromonedatatypetoanotherthroughassignment.Thereareimplicitand
explicitconversions.
Implicitconversionsarethosethatinvolvedirectassignmentofonetypetoanother.
14
R.V.College of Engineering
Dept. of MCA
Explicitconversionsareconversionsthatrequireonetypetobecastedasanothertype
inordertoperformtheconversion.Conversionsthatmaycauseexceptionsorresultin
lossofdataasthetypeisconvertedshouldbehandledasexplicitconversions.
Program:
usingSystem;
namespaceEx6
{
classComplex
{
publicdoublereal;
publicdoubleimag;
publicComplex(doublea,doubleb)
{
real=a;
imag=b;
}
publicComplex()
{
}
publicstaticComplexoperator+(ComplexC1,ComplexC2)
{
ComplexC3=newComplex(C1.real+C2.real,C1.imag+C2.imag);
returnC3;
}
publicstaticComplexoperator(ComplexC1,ComplexC2)
{
ComplexC3=newComplex(C1.realC2.real,C1.imagC2.imag);
returnC3;
}
15
publicoverridestringToString()
{
strings;
if(imag>0)
s=real.ToString()+"+"+imag.ToString()+"i";
else
R.V.College of Engineering
Dept. of MCA
s=real.ToString()+""+Math.Abs(imag).ToString()+"i";
returns;
classMainClass
{
publicstaticvoidMain(string[]args)
{
ComplexC1=newComplex(10,20);
ComplexC2=newComplex(5,10);
ComplexC3=C1+C2;
ComplexC4=C1C2;
Console.WriteLine("C1:"+C1.ToString()+"\nC2:"+C2.ToString()
+"\nC3=C1+C2:"+C3.ToString()+"\nC4=C1C2:"+C4.ToString());
}
}
}
TestData:
C1=10+20i
C2=5+10i
C3=C1+C2=15+30i
C4=C1C2=5+10i
4.Findthesumofalltheelementspresentinajaggedarrayof3innerarrays.
Ajaggedarrayisanarraywhoseelementsarearrays.Theelementsofajaggedarraycan
beofdifferentdimensionsandsizes.Ajaggedarrayissometimescalledan"arrayof
arrays."
Thefollowingisadeclarationofasingledimensionalarraythathasthreeelements,each
ofwhichisasingledimensionalarrayofintegers:
int[][]jaggedArray=newint[3][];
BeforeusingjaggedArray,itselementsmustbeinitialized.
jaggedArray[0]=newint[5];
jaggedArray[1]=newint[4];
jaggedArray[2]=newint[2];
16
R.V.College of Engineering
Dept. of MCA
Eachoftheelementsisasingledimensionalarrayofintegers.Thefirstelementisan
arrayof5integers,thesecondisanarrayof4integers,andthethirdisanarrayof2
integers.Itisalsopossibletouseinitializerstofillthearrayelementswithvalues,in
whichcasethearraysizeisnotneeded.Forexample:
jaggedArray[0]=newint[]{1,3,5,7,9};
jaggedArray[1]=newint[]{0,2,4,6};
jaggedArray[2]=newint[]{11,22};
Thiswayalsothearraycanbeinitialized:
int[][]jaggedArray2=newint[][]
{
newint[]{1,3,5,7,9},
newint[]{0,2,4,6},
newint[]{11,22}
};
Program:
usingSystem;
publicclassJaggedArrayDemo
{
publicstaticvoidMain()
{
intsum=0;
int[][]arr=newint[3][];
arr[0]=newint[3];
arr[1]=newint[5];
arr[2]=newint[2];
for(inti=0;i<arr.Length;i++)
{
Console.WriteLine("EntertheSizeoftheInnerArray"+(i+1)+":");
arr[i]=newint[int.Parse(Console.ReadLine())];
Console.WriteLine("EnterelementsforInnerArray"+arr[i].Length+":");
for(intj=0;j<arr[i].Length;j++)
{
arr[i][j]=int.Parse(Console.ReadLine());
sum+=arr[i][j];
}
}
17
R.V.College of Engineering
Dept. of MCA
Console.WriteLine("TheSumis="+sum);
}
}
TestData:
EnterthesizeoftheInnerArray1:
2
EnterelementsforinnerArray1:
1
1
EnterthesizeoftheInnerArray2:
1
EnterelementsforinnerArray2:
1
EnterthesizeoftheInnerArray3:
1
EnterelementsforinnerArray3:
1
Thesumis:4
5.UsingTry,CatchandFinallyblockswriteaprograminC#todemonstrateerror
handling.
The .NET platform provides a standard technique to send and trap runtime errors:
structuredexceptionhandling(SEH).Developersnowhaveaunifiedapproachtoerror
handling,whichiscommontoalllanguagestargetingthe.NETuniverse.Thesyntax
used to throw and catch exceptions across assemblies and machine boundaries is
identical. Another bonus of .NET exceptions is the fact that rather than receiving a
crypticnumericalvaluethatidentifiestheproblemathand,exceptionsareobjectsthat
containahumanreadabledescriptionoftheproblem,aswellasadetailedsnapshotof
thecallstackthattriggeredtheexceptioninthefirstplace.Thisinvolvestheuseoffour
interrelatedentities:
Aclasstypethatrepresentsthedetailsoftheexceptionthatoccurred
Amemberthatthrowsaninstanceoftheexceptionclasstothecaller
Ablockofcodeonthecallerssidethatinvokestheexceptionpronemember
Ablockofcodeonthecallerssidethatwillprocess(orcatch)theexceptionshouldit
occur
Program:
usingSystem;
classProgram
18
R.V.College of Engineering
Dept. of MCA
{
publicstaticvoidMain()
{
try
{
inta=10b=0,c;
c=a/b;
Console.WriteLine(C=a/b=,c);
}
catch(DivideByZeroExceptiondbze)
{
Console.WriteLine("Divisionbyzero!");
}
Try
{
Strings=Malayalam);
Strings1=s+s[11];
}
catch(IndexOutOfRangeExceptioniore)
{
Console.WriteLine("ArrayIndexoutofrange);
}
finally
{
Console.WriteLine("Exceptionhandlinghasbeendemonstrated");
}
}
}
TestData:
Divisionbyzero!
ArrayIndexoutofrange
Exceptionhandlinghasbeendemonstrated
6.DemonstrateUseofVirtualandoverridekeywordsinC#withasimpleProgram
OverrridingmethodisbasicallyruntimepolymorphisminC#.Whenasubclasscontains
amethodwiththesamenameandsignatureasinthesupperclassthenitiscalledas
methodoverriding.
Virtualmethodisamethodinabaseclasswhichthechildclasscanreuseitorredefine
andcustomizeitsbehaviortobeappropriatetoitsfunctionality.Thevirtualkeywordis
19
R.V.College of Engineering
Dept. of MCA
usedtomodifyamethod,property,indexeroreventdeclaration,andallowittobe
overriddeninaderivedclass.Forexample,thismethodcanbeoverriddenbyanyclass
thatinheritsit:
publicvirtualdoubleArea()
{
returnx*y;
}
Theimplementationofavirtualmembercanbechangedbyanoverridingmemberina
derivedclass.
Whenavirtualmethodisinvoked,theruntimetypeoftheobjectischeckedforan
overridingmember.
Theoverridingmemberinthemostderivedclassiscalled,whichmightbetheoriginal
member,ifnoderivedclasshasoverriddenthemember.
Bydefault,methodsarenonvirtual.Onecannotoverrideanonvirtualmethod.
Youcannotusethevirtualmodifierwiththestatic,abstract,privateoroverride
modifiers.
Avirtualinheritedpropertycanbeoverriddeninaderivedclassbyincludingaproperty
declarationthatusestheoverridemodifier.
Theoverridemodifierisrequiredtoextendormodifytheabstractorvirtual
implementationofaninheritedmethod,property,indexer,orevent.
Anoverridemethodprovidesanewimplementationofamemberinheritedfromabase
class.
Themethodoverriddenbyanoverridedeclarationisknownastheoverriddenbase
method.
Theoverriddenbasemethodmusthavethesamesignatureastheoverridemethod.
Program:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceVirtualnride
{
classA
{
Privateintx;
PublicA(intX){x=X;}
Publicvirtualvoiddisplay(){
Console.WriteLine(x=+x);
20
R.V.College of Engineering
Dept. of MCA
}
classB:A
{
Privateinty;
PublicB(intX,intY):base(X){y=Y;}
Publicoverridevoiddisplay(){
Base.display();
Console.WriteLine(y=+y);
}
}
classProgram
{
staticvoidMain(string[]args)
{
Aobj=newA(10);
Aobj=newB(10,20);
Console.WriteLine(ForobjectoftypeclassA:);
obj.display();
Console.WriteLine(ForobjectoftypeclassB:);
obj1.display();
}
}
TestData:
ForobjectoftypeclassA:
x=10
ForobjectoftypeclassA:
x=10
y=20
21
R.V.College of Engineering
Dept. of MCA
7Writeaprogramtodemonstratedelegates
DelegatesaresimilartoC++functionpointers,butaretypesafe.
Delegategivesanametoamethodsignature.
Delegatesallowmethodstobepassedasparameters.
Delegatescanbeusedtodefinecallbackmethods.
Delegatescanbechainedtogether;forexample,multiplemethodscanbecalledona
singleevent.
C#version2.0introducestheconceptofAnonymousMethods,whichpermitcodeblocks
tobepassedasparametersinplaceofaseparatelydefinedmethod.
Delegatehelpsincodeoptimization.
singSystem;
delegateintNumberChanger(intn);
namespaceDelegateAppl
{
classTestDelegate
{
staticintnum=10;
publicstaticintAddNum(intp)
{
num+=p;
returnnum;
}
publicstaticintMultNum(intq)
{
num*=q;
returnnum;
}
publicstaticintgetNum()
{
returnnum;
}
staticvoidMain(string[]args)
{
//createdelegateinstances
NumberChangernc;
NumberChangernc1=newNumberChanger(AddNum);
NumberChangernc2=newNumberChanger(MultNum);
nc=nc1;
22
R.V.College of Engineering
Dept. of MCA
nc+=nc2;//addingdelegate
//callingmulticast
nc(5);
Console.WriteLine("ValueofNum:{0}",getNum());
Console.ReadKey();
}
}
}
output:
ValueofNum:75
8.WriteaprogramtodemonstrateabstractclassandabstractmethodsinC#.
Abstractclassesareoneoftheessentialbehaviorsprovidedby.NET.Commonly,you
wouldliketomakeclassesthatonlyrepresentbaseclasses,anddontwantanyoneto
createobjectsoftheseclasstypes.Herewemakeuseofabstractclassestoimplement
suchfunctionalityinC#usingthemodifier'abstract'.
Anabstractclassmeansthat,noobjectofthisclasscanbeinstantiated,butcanmake
derivationsofthis.Anabstractclasscancontaineitherabstractornonabstractmethods.
Abstractmembersdonothaveanyimplementationintheabstractclass,butthesamehastobe
providedinitsderivedclass.
Program:
usingSystem;
namespaceAbstract
{
publicabstractclassAdd
{
publicabstractvoidreadandadd();
publicabstractvoiddisplay();
}
publicclassBinAdd:Add
{
Privatedoublea,b,c;
publicoverridevoidreadandadd()
{
Console.WriteLind(Entervalueofa:);
a=double.Parse(Console.ReadLine());
Console.WriteLind(Entervalueofb:);
b=double.Parse(Console.ReadLine());
23
R.V.College of Engineering
}
Dept. of MCA
c=a+b;
publicoverridevoiddisplay()
{
Console.WriteLine("Valueofa({0})+b({1})=c{2},a,b,c);
}
}
publicclassProgram
{
publicstaticvoidMain(string[]args)
{
BinAddb=newBinAdd();
b.readamdadd();
b.display();
}
}
Testdata:
Enterthevalueofa:
4
Enterthevalueofb:
3
Valueofa(4)+b(3)=7
9.WriteaprogramtoillustratetheuseofdifferentpropertiesinC#.
Incontrasttotraditionalaccessorandmutatormethods,.NETlanguagespreferto
enforceencapsulationusingproperties,whichsimulatepubliclyaccessiblepointsofdata.
Ratherthanrequiringtheusertocalltwodifferentmethodstogetandsetthestatedata,
theuserisabletocallwhatappearstobeapublicfield.AC#propertyiscomposed
usingagetblock(accessor)andsetblock(mutator).
Propertiesenableaclasstoexposeapublicwayofgettingandsettingvalues,while
hidingimplementationorverificationcode.Thegetpropertyaccessorisusedtoreturn
thepropertyvalue,andasetaccessorisusedtoassignanewvalue.Theseaccessorscan
havedifferentaccesslevels.Thevaluekeywordisusedtodefinethevaluebeing
assignedbythesetindexer.
Propertiesthatdonotimplementasetmethodarereadonly.
Thecodeblockforthegetaccessorisexecutedwhenthepropertyisread;thecode
blockforthesetaccessorisexecutedwhenthepropertyisassignedanewvalue.
Apropertywithoutasetaccessorisconsideredreadonly.Apropertywithoutaget
accessorisconsideredwriteonly.Apropertywithbothaccessorsisreadwrite.
Program:
24
R.V.College of Engineering
Dept. of MCA
usingSystem;
classstudent
{
privateStringusn;
privateStringName;
privatedoubleperc;
privateboolvalidated;
privatestaticStringcollegeName=RVCE;
publicStudent(StringUSN){usn=USN;}
publicstaticStringCollegeName{get{returncollegeName;}}
publicStringUSN
{
get{returnusn;}
}
publicstringName
{
get{returnname;}
set{name=value;}
}
publicdoublepercentage
{
get{returnperc;}
set{perc=value;}
}
publicboolvalidated{
set{validated=value;}
}
}
}
classProgram
{
publicstaticvoidMain(String[]args)
{
Students=newstudent("1RV13MCA01");
s.name="Ram";
s.percentage=79.0;
s.validated()=true;
Consolidated.WriteLine(Afterusingaccessorsandmutators:);
Consolidated.WriteLine(Collegename:{0},Student.CollegeName);
Consolidated.WriteLine(USN:{0},s.USN);
Consolidated.WriteLine(Name:{0},s.Name);
25
R.V.College of Engineering
Dept. of MCA
Consolidated.WriteLine(Percentage:{0},s.Percentage);
}
}
Testdata:
Afterusingaccessorsandmutators:
Collegename:RVCE
USN:1RV13MCA01
Name:Ram
Percentage:79.0
10Demonstratearraysofinterfacetypes(forruntimepolymorphism)withaC#
program.
usingSystem;
usingSystem.Collections.Generic;
namespaceInterfaces
{
classProgram
{
staticvoidMain(string[]args)
{
List<Dog>dogs=newList<Dog>();
dogs.Add(newDog("Fido"));
dogs.Add(newDog("Bob"));
dogs.Add(newDog("Adam"));
dogs.Sort();
foreach(Dogdogindogs)
Console.WriteLine(dog.Describe());
Console.ReadKey();
}
}
interfaceIAnimal
{
stringDescribe();
26
R.V.College of Engineering
Dept. of MCA
stringName
{
get;
set;
}
}
classDog:IAnimal,IComparable
{
privatestringname;
publicDog(stringname)
{
this.Name=name;
}
publicstringDescribe()
{
return"Hello,I'madogandmynameis"+this.Name;
}
publicintCompareTo(objectobj)
{
if(objisIAnimal)
returnthis.Name.CompareTo((objasIAnimal).Name);
return0;
}
publicstringName
{
get{returnname;}
set{name=value;}
}
}
}
27
R.V.College of Engineering
Dept. of MCA
PARTB
28
R.V.College of Engineering
Dept. of MCA
1.considertheDatabaseSTUDENTconsistingoffollowingtables:tbl_Course
(CourseID:int,CourseName:string)tbl_Student(USN:string,StudName:string,
Address:string,CourseID:int,YrOfAdmsn:int)
DevelopsuitablewindowsapplicationusingC#.NEThavingfollowingoptions:
1.Enteringnewcoursedetails.
2.Enteringnewstudentdetails.
3.Displaythedetailsofstudents(inaGrid)whobelongtoaparticularcourse.
4.Displaythedetailsthestudentswhohavetakenadmissioninaparticularyear.
Form1
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceWindowsFormsApplication1
{
publicpartialclassfrmMDIMain:Form
{
publicfrmMDIMain()
{
InitializeComponent();
}
privatevoidForm1_Load(objectsender,EventArgse)
{
}
privatevoidnewToolStripMenuItem_Click(objectsender,EventArgse)
{
}
Form2f2;
privatevoidstudentToolStripMenuItem_Click(objectsender,EventArgse)
{
29
R.V.College of Engineering
Dept. of MCA
if(f2==null)
{
f2=newForm2();
f2.MdiParent=this;
f2.Dock=DockStyle.Fill;
f2.Show();
f2.FormClosed+=newFormClosedEventHandler(f2_FormClosed);
}
else
{
f2.Activate();
}
}
voidf2_FormClosed(objectsender,FormClosedEventArgse)
{
f2=null;
}
Form3f3;
privatevoidcourseToolStripMenuItem_Click(objectsender,EventArgse)
{
if(f3==null)
{
f3=newForm3();
f3.MdiParent=this;
f3.Dock=DockStyle.Fill;
f3.Show();
f3.FormClosed+=newFormClosedEventHandler(f3_FormClosed);
}
else
f3.Activate();
}
voidf3_FormClosed(objectsender,FormClosedEventArgse)
{
f3=null;
}
}
}
Form2
30
R.V.College of Engineering
Dept. of MCA
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMySql.Data.MySqlClient;
namespaceWindowsFormsApplication1
{
publicpartialclassForm2:Form
{
StringConnectionString="Server=localhost;Database=student;Uid=root;Pwd=harish;";
MySqlConnectioncon;
MySqlCommandcmd;
publicForm2()
{
InitializeComponent();
con=newMySqlConnection(ConnectionString);
}
privatevoidForm2_Load(objectsender,EventArgse)
{
}
31
R.V.College of Engineering
Dept. of MCA
privatevoidbutton1_Click(objectsender,EventArgse)
{
con.Open();
try
{
cmd=con.CreateCommand();
cmd.CommandText="INSERTINTOstudent(usn,name,address,yearofadm,courseID)
VALUES(?usn,?name,?address,?yearofadm,?courseID)";
cmd.Prepare();
//System.Console.WriteLine(""+textBox2.Text+textBox1.Text+
textBox5.Text);
cmd.Parameters.AddWithValue("?usn",textBox2.Text);
cmd.Parameters.AddWithValue("?name",textBox1.Text);
cmd.Parameters.AddWithValue("?address",textBox5.Text);
cmd.Parameters.AddWithValue("?yearofadm",int.Parse(textBox3.Text));
cmd.Parameters.AddWithValue("?courseID",int.Parse(textBox4.Text));
System.Console.WriteLine(""+textBox2.Text+textBox1.Text+
textBox5.Text);
cmd.ExecuteNonQuery();
}
catch(Exception)
{
throw;
}
finally
{
textBox1.Clear();
textBox2.Clear();
32
R.V.College of Engineering
Dept. of MCA
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
con.Close();
}
}
privatevoidbutton2_Click(objectsender,EventArgse)
{
}
privatevoidsearch_Click(objectsender,EventArgse)
{
con.Open();
MySqlDataAdapteradapter=null;
if(radiocourse.Checked==true)
{
adapter=newMySqlDataAdapter("select*fromstudentwherecourseID='"+
searchtext.Text+"'",con);
}
else
{
adapter=newMySqlDataAdapter("select*fromstudentwhereyearofadm='"+
searchtext.Text+"'",con);
}
DataSetds=newDataSet();
adapter.Fill(ds,"student");
dataGridView1.DataSource=ds.Tables["student"];
con.Close();
}
33
R.V.College of Engineering
Dept. of MCA
privatevoidsearchAll_Click(objectsender,EventArgse)
{
con.Open();
MySqlDataAdapteradapter=newMySqlDataAdapter("select*fromstudent",con);
DataSetds=newDataSet();
adapter.Fill(ds,"student");
dataGridView1.DataSource=ds.Tables["student"];
con.Close();
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMySql.Data.MySqlClient;
namespaceWindowsFormsApplication1
{
publicpartialclassForm3:Form
{
StringConnectionString="Server=localhost;Database=student;Uid=root;Pwd=harish;";
MySqlConnectioncon;
MySqlCommandcmd;
34
R.V.College of Engineering
Dept. of MCA
publicForm3()
{
InitializeComponent();
con=newMySqlConnection(ConnectionString);
}
privatevoidAdd_Click(objectsender,EventArgse)
{
con.Open();
try
{
cmd=con.CreateCommand();
cmd.CommandText="INSERTINTOcourse(courseID,courseName)VALUES(?
courseID,?courseName)";
cmd.Prepare();
cmd.Parameters.AddWithValue("?courseId",courseID.Text);
cmd.Parameters.AddWithValue("?courseName",courseName.Text);
cmd.ExecuteNonQuery();
}
catch(Exception)
{
throw;
}
finally
{
courseID.Clear();
courseName.Clear();
con.Close();
35
R.V.College of Engineering
Dept. of MCA
}
}
privatevoiddataGridView1_CellContentClick(objectsender,DataGridViewCellEventArgse)
{
}
privatevoidshow_Click(objectsender,EventArgse)
{
MySqlDataAdapteradapter=newMySqlDataAdapter("select*fromcourse",con);
DataSetds=newDataSet();
adapter.Fill(ds,"c");
dataGridView1.DataSource=ds.Tables["c"];
con.Close();
}
}
}
Fig1:StudentForm
36
R.V.College of Engineering
Dept. of MCA
Fig2:CourseForm
2ConsidertheDatabaseSTUDENTconsistingoffollowingtables:
ConsidertheDatabaseBLOODBANKconsistingoffollowingtables:tbl_BloodGroup
(BloodID:int,BloodGroup:string)tbl_Donor(DonorID:int,DonorName:stirng,
Address:string,ContactNo:int,DOB:date,Gender:string,Weight:int,BloodID:
int)
DevelopsuitablewindowsapplicationusingC#.NEThavingfollowingoptions:
1.EnteringBloodgroupdetails.
2.Enteringnewdonordetails.
3.Displaythedetailsofdonors(inaGrid)havingparticularbloodgroup.
4.Displaythedetailsofdonors(inaGrid)basedongender.
37
R.V.College of Engineering
Dept. of MCA
5.Displaythedetailsofdonors(inaGrid)basedonage(above18),weight(above
45KG)andGender(userschoice).
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceBloodBank
{
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
}
privatevoidForm1_Load(objectsender,EventArgse)
{
}
bloodgroupform;
privatevoidaddToolStripMenuItem_Click(objectsender,EventArgse)
{
if(form==null)
{
form=newbloodgroup();
form.MdiParent=this;
form.Dock=DockStyle.Fill;
form.Show();
form.FormClosed+=newFormClosedEventHandler(form_FormClosed);
}
else
form.Activate();
}
voidform_FormClosed(objectsender,FormClosedEventArgse)
{
form=null;
}
38
R.V.College of Engineering
Dept. of MCA
Donordonorform;
privatevoidnewDonorToolStripMenuItem_Click(objectsender,EventArgse)
{
if(donorform==null)
{
donorform=newDonor();
donorform.MdiParent=this;
donorform.Dock=DockStyle.Fill;
donorform.Show();
}
else
donorform.Activate();
donorform.FormClosed+=newFormClosedEventHandler(donorform_FormClosed);
}
voiddonorform_FormClosed(objectsender,FormClosedEventArgse)
{
donorform=null;
}
}
}
Form2
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMySql.Data.MySqlClient;
namespaceBloodBank
{
publicpartialclassbloodgroup:Form
{
StringConnectionString=
"Server=localhost;Database=bloodbank;Uid=root;Pwd=harish;";
MySqlConnectioncon;
MySqlCommandcmd;
publicbloodgroup()
{
InitializeComponent();
con=newMySqlConnection(ConnectionString);
}
39
R.V.College of Engineering
Dept. of MCA
privatevoidAdd_Click(objectsender,EventArgse)
{
cmd=con.CreateCommand();
con.Open();
cmd.CommandText="INSERTINTObloodgroup(bloodid,bloodgroup)VALUES(?
bloodid,?bloodgroup)";
cmd.Parameters.AddWithValue("?bloodid",int.Parse(bloodidtext.Text));
cmd.Parameters.AddWithValue("?bloodgroup",bloodgrouptext.Text);
cmd.ExecuteNonQuery();
con.Close();
bloodgrouptext.Clear();
bloodidtext.Clear();
}
privatevoidDelete_Click(objectsender,EventArgse)
{
}
privatevoidSearchAll_Click(objectsender,EventArgse)
{
con.Open();
MySqlDataAdapteradapter=newMySqlDataAdapter("Select*frombloodgroup",con);
DataSetds=newDataSet();
adapter.Fill(ds,"bloodgroup");
dataGridView1.DataSource=ds.Tables["bloodgroup"];
con.Close();
}
}
}
Form3
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMySql.Data.MySqlClient;
40
R.V.College of Engineering
Dept. of MCA
namespaceBloodBank
{
publicpartialclassDonor:Form
{
StringConnectionString=
"Server=localhost;Database=bloodbank;Uid=root;Pwd=harish;";
Stringcombovalue;
MySqlConnectioncon;
MySqlCommandcmd;
publicDonor()
{
InitializeComponent();
con=newMySqlConnection(ConnectionString);
fillComboBoxBloodid();
}
privatevoidlabel1_Click(objectsender,EventArgse)
{
}
privatevoidAdd_Click(objectsender,EventArgse)
{
con.Open();
cmd=con.CreateCommand();
cmd.CommandText="INSERTINTO
donor(donorid,donorname,address,contactno,dob,gender,weight,bloodid)VALUES(?donorid,?
donorname,?address,?contactno,?dob,?gender,?weight,?bloodid)";
cmd.Parameters.AddWithValue("?donorid",int.Parse(DonorID.Text));
cmd.Parameters.AddWithValue("?donorname",DonorName.Text);
cmd.Parameters.AddWithValue("?address",address.Text);
cmd.Parameters.AddWithValue("?contactno",int.Parse(contact.Text));
cmd.Parameters.AddWithValue("?dob",Convert.ToDateTime(dob.Text));
if(male.Checked)
cmd.Parameters.AddWithValue("?gender","male");
else
cmd.Parameters.AddWithValue("?gender","female");
cmd.Parameters.AddWithValue("?weight",int.Parse(weight.Text));
cmd.Parameters.AddWithValue("?bloodid",int.Parse(combovalue));
cmd.ExecuteNonQuery();
con.Close();
}
privatevoidDonor_Load(objectsender,EventArgse)
{
fillComboBoxBloodid();
41
R.V.College of Engineering
Dept. of MCA
fillComboBoxBloodsearch();
}
privatevoidSearchALL_Click(objectsender,EventArgse)
{
con.Open();
MySqlDataAdapteradapter=newMySqlDataAdapter("Select*fromdonor",con);
DataSetds=newDataSet();
adapter.Fill(ds,"donor");
dataGridView1.DataSource=ds.Tables["donor"];
con.Close();
}
privatevoidcomboBoxBloodId_SelectedIndexChanged(objectsender,EventArgse)
{
combovalue=comboBoxBloodId.SelectedValue.ToString();
}
privatevoidfillComboBoxBloodid()
{
//con.Open();
MySqlDataAdaptersqlgender=newMySqlDataAdapter("Select*frombloodgroup",
con);
DataTabledtgen=newDataTable("bloodid");
sqlgender.Fill(dtgen);
comboBoxBloodId.DataSource=dtgen;
comboBoxBloodId.DisplayMember="bloodgroup";
comboBoxBloodId.ValueMember="bloodid";
con.Close();
}
privatevoidfillComboBoxBloodsearch()
{
//con.Open();
MySqlDataAdaptersqlgender=newMySqlDataAdapter("Select*frombloodgroup",
con);
DataTabledtgen=newDataTable("bloodid");
sqlgender.Fill(dtgen);
searchbloodcombo.DataSource=dtgen;
searchbloodcombo.DisplayMember="bloodgroup";
searchbloodcombo.ValueMember="bloodid";
con.Close();
42
R.V.College of Engineering
Dept. of MCA
privatevoidDonor_Activated(objectsender,System.EventArgse)
{
fillComboBoxBloodid();
}
privatevoidsearchbygroup_Click(objectsender,EventArgse)
{
con.Open();
MySqlDataAdapteradapter=newMySqlDataAdapter("Select*fromdonorwhere
bloodid='"+combovalue+"'",con);
DataSetds=newDataSet();
adapter.Fill(ds,"donor");
dataGridView1.DataSource=ds.Tables["donor"];
con.Close();
}
privatevoidsearchbloodcombo_SelectedIndexChanged(objectsender,EventArgse)
{
combovalue=searchbloodcombo.SelectedValue.ToString();
}
privatevoidsearchbygender_Click(objectsender,EventArgse)
{
MySqlDataAdapteradapter=null;
con.Open();
if(radiomalesearch.Checked)
adapter=newMySqlDataAdapter("Select*fromdonorwheregender='male'",con);
else
adapter=newMySqlDataAdapter("Select*fromdonorwheregender='female'",con);
DataSetds=newDataSet();
adapter.Fill(ds,"gendersearch");
dataGridView1.DataSource=ds.Tables["gendersearch"];
con.Close();
}
privatevoidSearchByAgeWeight_Click(objectsender,EventArgse)
{
MySqlDataAdapteradapter=null;
con.Open();
if(radiomalesearch.Checked)
43
R.V.College of Engineering
Dept. of MCA
adapter=newMySqlDataAdapter("SELECT*,YEAR(CURDATE())YEAR(dob)
IF(STR_TO_DATE(CONCAT(YEAR(CURDATE()),'',MONTH(dob),'',IF(MONTH(dob)=2AND
DAY(dob)=29,DAY(DATE_ADD(CONCAT(YEAR(CURDATE()),'0301'),INTERVAL1
DAY)),DAY(dob))),'%Y%c%e')>CURDATE(),1,0)ASageFROMdonorhavingage>30
andgender='male'andweight>45",con);
else
adapter=newMySqlDataAdapter("SELECT*,YEAR(CURDATE())YEAR(dob)
IF(STR_TO_DATE(CONCAT(YEAR(CURDATE()),'',MONTH(dob),'',IF(MONTH(dob)=2AND
DAY(dob)=29,DAY(DATE_ADD(CONCAT(YEAR(CURDATE()),'0301'),INTERVAL1
DAY)),DAY(dob))),'%Y%c%e')>CURDATE(),1,0)ASageFROMdonorhavingage>30
andgender='female'andweight>45",con);
DataSetds=newDataSet();
adapter.Fill(ds,"searchageandweight");
dataGridView1.DataSource=ds.Tables["searchageandweight"];
con.Close();
}
}
}
Fig3:BloodGroupForm
44
R.V.College of Engineering
Dept. of MCA
Fig4:DonorForm
45
R.V.College of Engineering
Dept. of MCA
3.ConsidertheDatabaseSTUDENTconsistingoffollowingtables:tbl_Course
(CourseID:int,CourseName:string)tbl_Book(BookID:int,BookTitle:string,
Author:string,CourseID:int)tbl_Student(USN:string,StudName:string,
CourseID:int)tbl_BookIssue(USN:string,BookID:int,IssueDate:Date)
DevelopsuitablewindowsapplicationusingC#.NEThavingfollowingoptions:
1.NewCourseEntry.
2.NewBookEntry
3.NewStudentEntry
4.Issueofbookstoastudent.
5.Generatereport(displayinagrid)showingallthebooksbelongingtoparticular
course.
6.Generatereport(displayinagrid)showingallthebooksissuedonaparticulardate.
7.Generatereport(displayinagrid)showingallthebooksissuedtoaparticular
student.
Fig1:MainForm
46
R.V.College of Engineering
Dept. of MCA
2NewBook
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMySql.Data;
usingMySql.Data.MySqlClient;
namespacestudentdatabase
{
publicpartialclassBookEntry:Form
{
privatestringserver;
privatestringdatabase;
privatestringuid;
privatestringpassword;
privateMySqlConnectionconnection;
privateMySqlDataAdaptermySqlDataAdapter;
publicBookEntry()
47
R.V.College of Engineering
Dept. of MCA
{
InitializeComponent();
}
privatevoidBookEntry_Load(objectsender,EventArgse)
{
load_grid();
load_combo();
}
privatevoidload_combo()
{
server="localhost";
database="student";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+
";"+"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
if(this.OpenConnection()==true)
{
mySqlDataAdapter=newMySqlDataAdapter("select*fromtbl_course",
connection);
48
R.V.College of Engineering
Dept. of MCA
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
courseid.DataSource=DS.Tables[0];
courseid.DisplayMember="coursename";
courseid.ValueMember="courseid";
//closeconnection
this.CloseConnection();
}
}
privatevoidload_grid()
{
server="localhost";
database="student";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+
";"+"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
if(this.OpenConnection()==true)
{
49
R.V.College of Engineering
Dept. of MCA
mySqlDataAdapter=newMySqlDataAdapter("select*fromtbl_book",
connection);
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
dataGridView1.DataSource=DS.Tables[0];
//closeconnection
this.CloseConnection();
}
}
privateboolOpenConnection()
{
try
{
connection.Open();
returntrue;
}
catch(MySqlExceptionex)
{
//Whenhandlingerrors,youcanyourapplication'sresponsebasedonthe
errornumber.
//Thetwomostcommonerrornumberswhenconnectingareasfollows:
//0:Cannotconnecttoserver.
//1045:Invalidusernameand/orpassword.
50
R.V.College of Engineering
Dept. of MCA
switch(ex.Number)
{
case0:
MessageBox.Show("Cannotconnecttoserver.Contactadministrator");
break;
case1045:
MessageBox.Show("Invalidusername/password,pleasetryagain");
break;
default:
MessageBox.Show(ex.Message);
break;
}
returnfalse;
}
}
privateboolCloseConnection()
{
try
{
connection.Close();
returntrue;
}
51
R.V.College of Engineering
Dept. of MCA
catch(MySqlExceptionex)
{
MessageBox.Show(ex.Message);
returnfalse;
}
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
server="localhost";
database="student";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+
";"+"UID="+uid+";"+"PASSWORD="+password+";";
stringquery="INSERTINTO
tbl_book(bookid,booktitle,author,courseid)VALUES(?bookid,?booktitle,?author,?
courseid);";
using(connection=newMySqlConnection(connectionString))
{
MySqlCommandinsertCommand=newMySqlCommand(query,connection);
insertCommand.Parameters.AddWithValue("?bookid",int.Parse(bookid.Text));
52
R.V.College of Engineering
Dept. of MCA
insertCommand.Parameters.AddWithValue("?booktitle",booktitle.Text);
insertCommand.Parameters.AddWithValue("?author",author.Text);
insertCommand.Parameters.AddWithValue("?
courseid",int.Parse(courseid.SelectedValue.ToString()));
try
{
connection.Open();
insertCommand.ExecuteNonQuery();
load_grid();
MessageBox.Show("inserted");
}
catch(Exceptionex)
{
Console.WriteLine("exception:"+ex);
}
connection.Close();
}
}
53
R.V.College of Engineering
Dept. of MCA
3.NewStudent
usingSystem;
usingSystem.Collections.Generic;
54
R.V.College of Engineering
Dept. of MCA
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMySql.Data;
usingMySql.Data.MySqlClient;
namespacestudentdatabase
{
publicpartialclassForm2:Form
{
privatestringserver;
privatestringdatabase;
privatestringuid;
privatestringpassword;
privateMySqlConnectionconnection;
privateMySqlDataAdaptermySqlDataAdapter;
publicForm2()
{
InitializeComponent();
55
R.V.College of Engineering
Dept. of MCA
privatevoidInsert_Click(objectsender,EventArgse)
{
server="localhost";
database="student";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+
";"+"UID="+uid+";"+"PASSWORD="+password+";";
stringquery="INSERTINTOtbl_course(courseid,coursename)VALUES(?
courseid,?coursename);";
using(connection=newMySqlConnection(connectionString))
{
MySqlCommandinsertCommand=newMySqlCommand(query,connection);
insertCommand.Parameters.AddWithValue("?courseid",
int.Parse(courseid.Text));
insertCommand.Parameters.AddWithValue("?coursename",coursename.Text);
try
{
connection.Open();
56
R.V.College of Engineering
Dept. of MCA
insertCommand.ExecuteNonQuery();
load_grid();
MessageBox.Show("inserted");
}
catch(Exceptionex)
{
Console.WriteLine("exception:"+ex);
}
connection.Close();
}
}
privateboolOpenConnection()
{
try
{
connection.Open();
returntrue;
}
catch(MySqlExceptionex)
{
57
R.V.College of Engineering
Dept. of MCA
//Whenhandlingerrors,youcanyourapplication'sresponsebasedonthe
errornumber.
//Thetwomostcommonerrornumberswhenconnectingareasfollows:
//0:Cannotconnecttoserver.
//1045:Invalidusernameand/orpassword.
switch(ex.Number)
{
case0:
MessageBox.Show("Cannotconnecttoserver.Contactadministrator");
break;
case1045:
MessageBox.Show("Invalidusername/password,pleasetryagain");
break;
default:
MessageBox.Show(ex.Message);
break;
}
returnfalse;
}
}
privateboolCloseConnection()
{
try
58
R.V.College of Engineering
Dept. of MCA
{
connection.Close();
returntrue;
}
catch(MySqlExceptionex)
{
MessageBox.Show(ex.Message);
returnfalse;
}
}
privatevoidload_grid()
{
server="localhost";
database="student";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+
";"+"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
if(this.OpenConnection()==true)
{
59
R.V.College of Engineering
Dept. of MCA
mySqlDataAdapter=newMySqlDataAdapter("select*fromtbl_course",
connection);
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
dataGridView1.DataSource=DS.Tables[0];
//closeconnection
this.CloseConnection();
}
privatevoidForm2_Load(objectsender,EventArgse)
{
load_grid();
}
}
}
60
R.V.College of Engineering
Dept. of MCA
4.Issueofbookstoastudent.
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMySql.Data;
usingMySql.Data.MySqlClient;
61
R.V.College of Engineering
Dept. of MCA
namespacestudentdatabase
{
publicpartialclassBookissue:Form
{
privatestringserver;
privatestringdatabase;
privatestringuid;
privatestringpassword;
privateMySqlConnectionconnection;
privateMySqlDataAdaptermySqlDataAdapter;
publicBookissue()
{
InitializeComponent();
}
privatevoidBookissue_Load(objectsender,EventArgse)
{
load_grid();
load_combo();
load_combo1();
}
privatevoidload_combo()
{
62
R.V.College of Engineering
Dept. of MCA
server="localhost";
database="student";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+
";"+"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
if(this.OpenConnection()==true)
{
mySqlDataAdapter=newMySqlDataAdapter("select*fromtbl_student",
connection);
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
usn.DataSource=DS.Tables[0];
usn.DisplayMember="studname";
usn.ValueMember="usn";
//closeconnection
this.CloseConnection();
}
}
privatevoidload_combo1()
63
R.V.College of Engineering
Dept. of MCA
{
server="localhost";
database="student";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+
";"+"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
if(this.OpenConnection()==true)
{
mySqlDataAdapter=newMySqlDataAdapter("select*fromtbl_book",
connection);
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
bookid.DataSource=DS.Tables[0];
bookid.DisplayMember="booktitle";
bookid.ValueMember="bookid";
//closeconnection
this.CloseConnection();
}
}
64
R.V.College of Engineering
Dept. of MCA
privatevoidload_grid()
{
server="localhost";
database="student";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+
";"+"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
if(this.OpenConnection()==true)
{
mySqlDataAdapter=newMySqlDataAdapter("select*fromtbl_bookissue",
connection);
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
dataGridView1.DataSource=DS.Tables[0];
//closeconnection
this.CloseConnection();
}
}
65
R.V.College of Engineering
Dept. of MCA
privateboolOpenConnection()
{
try
{
connection.Open();
returntrue;
}
catch(MySqlExceptionex)
{
//Whenhandlingerrors,youcanyourapplication'sresponsebasedonthe
errornumber.
//Thetwomostcommonerrornumberswhenconnectingareasfollows:
//0:Cannotconnecttoserver.
//1045:Invalidusernameand/orpassword.
switch(ex.Number)
{
case0:
MessageBox.Show("Cannotconnecttoserver.Contactadministrator");
break;
case1045:
MessageBox.Show("Invalidusername/password,pleasetryagain");
break;
default:
66
R.V.College of Engineering
Dept. of MCA
MessageBox.Show(ex.Message);
break;
}
returnfalse;
}
}
privateboolCloseConnection()
{
try
{
connection.Close();
returntrue;
}
catch(MySqlExceptionex)
{
MessageBox.Show(ex.Message);
returnfalse;
}
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
67
R.V.College of Engineering
Dept. of MCA
server="localhost";
database="student";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+
";"+"UID="+uid+";"+"PASSWORD="+password+";";
stringquery="INSERTINTOtbl_bookissue(usn,bookid,issuedate)VALUES(?
usn,?bookid,?issuedate);";
using(connection=newMySqlConnection(connectionString))
{
MySqlCommandinsertCommand=newMySqlCommand(query,connection);
insertCommand.Parameters.AddWithValue("?usn",
usn.SelectedValue.ToString());
insertCommand.Parameters.AddWithValue("?bookid",
int.Parse(bookid.SelectedValue.ToString()));
insertCommand.Parameters.AddWithValue("?issuedate",
date.Value.ToString("yyyyMMdd"));
try
{
connection.Open();
insertCommand.ExecuteNonQuery();
68
R.V.College of Engineering
Dept. of MCA
load_grid();
MessageBox.Show("inserted");
}
catch(Exceptionex)
{
Console.WriteLine("exception:"+ex);
}
connection.Close();
}
}
}
}
5.Generatereport(displayinagrid)showingallthebooksbelongingtoparticular
course.
69
R.V.College of Engineering
Dept. of MCA
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMySql.Data;
usingMySql.Data.MySqlClient;
namespacestudentdatabase
{
70
R.V.College of Engineering
Dept. of MCA
publicpartialclassReport:Form
{
privatestringserver;
privatestringdatabase;
privatestringuid;
privatestringpassword;
privateMySqlConnectionconnection;
privateMySqlDataAdaptermySqlDataAdapter;
publicReport()
{
InitializeComponent();
}
privatevoidload_combo()
{
server="localhost";
database="student";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+
";"+"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
71
R.V.College of Engineering
Dept. of MCA
if(this.OpenConnection()==true)
{
mySqlDataAdapter=newMySqlDataAdapter("select*fromtbl_course",
connection);
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
course.DataSource=DS.Tables[0];
course.DisplayMember="coursename";
course.ValueMember="courseid";
//closeconnection
this.CloseConnection();
}
}
privatevoidload_combo1()
{
server="localhost";
database="student";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+
";"+"UID="+uid+";"+"PASSWORD="+password+";";
72
R.V.College of Engineering
Dept. of MCA
connection=newMySqlConnection(connectionString);
if(this.OpenConnection()==true)
{
mySqlDataAdapter=newMySqlDataAdapter("select*fromtbl_student",
connection);
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
studname.DataSource=DS.Tables[0];
studname.DisplayMember="studname";
studname.ValueMember="usn";
//closeconnection
this.CloseConnection();
}
}
privateboolOpenConnection()
{
try
{
connection.Open();
returntrue;
}
catch(MySqlExceptionex)
73
R.V.College of Engineering
Dept. of MCA
{
//Whenhandlingerrors,youcanyourapplication'sresponsebasedonthe
errornumber.
//Thetwomostcommonerrornumberswhenconnectingareasfollows:
//0:Cannotconnecttoserver.
//1045:Invalidusernameand/orpassword.
switch(ex.Number)
{
case0:
MessageBox.Show("Cannotconnecttoserver.Contactadministrator");
break;
case1045:
MessageBox.Show("Invalidusername/password,pleasetryagain");
break;
default:
MessageBox.Show(ex.Message);
break;
}
returnfalse;
}
}
privateboolCloseConnection()
74
R.V.College of Engineering
Dept. of MCA
{
try
{
connection.Close();
returntrue;
}
catch(MySqlExceptionex)
{
MessageBox.Show(ex.Message);
returnfalse;
}
}
privatevoidReport_Load(objectsender,EventArgse)
{
load_combo();
load_combo1();
}
privatevoidcourse_SelectedIndexChanged(objectsender,EventArgse)
{
server="localhost";
database="student";
uid="root";
75
R.V.College of Engineering
Dept. of MCA
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+
";"+"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
if(this.OpenConnection()==true)
{
mySqlDataAdapter=newMySqlDataAdapter("select
bookid,booktitle,author,coursenamefromtbl_coursec,tbl_bookbwhere
c.courseid=b.courseidandcoursename='"+course.Text+"'",connection);
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
dataGridView1.DataSource=DS.Tables[0];
//closeconnection
this.CloseConnection();
}
privatevoidstudname_SelectedIndexChanged(objectsender,EventArgse)
{
server="localhost";
76
R.V.College of Engineering
Dept. of MCA
database="student";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+
";"+"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
if(this.OpenConnection()==true)
{
mySqlDataAdapter=newMySqlDataAdapter("select
b.bookid,s.usn,studname,booktitle,authorfromtbl_students,tbl_bookb,tbl_bookissuebi
wheres.usn=bi.usnandb.bookid=bi.bookidandstudname='"+studname.Text+"'",
connection);
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
dataGridView1.DataSource=DS.Tables[0];
//closeconnection
this.CloseConnection();
}
77
R.V.College of Engineering
Dept. of MCA
privatevoiddate_ValueChanged(objectsender,EventArgse)
{
server="localhost";
database="student";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+
";"+"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
if(this.OpenConnection()==true)
{
mySqlDataAdapter=newMySqlDataAdapter("select
b.bookid,s.usn,studname,booktitle,authorfromtbl_students,tbl_bookb,tbl_bookissuebi
wheres.usn=bi.usnandb.bookid=bi.bookidandbi.issuedate='"+
date.Value.ToString("yyyyMMdd")+"'",connection);
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
dataGridView1.DataSource=DS.Tables[0];
//closeconnection
this.CloseConnection();
}
}
78
R.V.College of Engineering
Dept. of MCA
}
}
6.Generatereport(displayinagrid)showingallthebooksissuedonaparticulardate.
7.Generatereport(displayinagrid)showingallthebooksissuedtoaparticular
student.
79
R.V.College of Engineering
Dept. of MCA
4.CreatingDatabase,TableandDesigningFormsandCode
DevelopaWebApplicationusingC#.NETandASP.NETforaneducationalinstitution.The
masterpageshouldconsistofInstitutionName,LogoandAddress.Also,itshouldprovide
hyperlinkstoDepartments,FacilitiesAvailableandFeedback.Eachdepartmentpageand
facilitiespageshouldbedesignedasstaticpages.Thehyperlinksshouldnavigatetothesestatic
pagesintheformofContentPagesassociatedwithMasterPagedesigned.TheFeedbackpage
shouldhavefieldstoenterName,EmailandMessagewithSubmitandCancelButtons.Database
shouldbecreatedtostorethesethreedata.
80
R.V.College of Engineering
Dept. of MCA
<%@PageTitle="HomePage"Language="C#"MasterPageFile="~/Site.master"
AutoEventWireup="true"
CodeFile="Default.aspx.cs"Inherits="_Default"%>
<asp:ContentID="HeaderContent"runat="server"ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:ContentID="BodyContent"runat="server"ContentPlaceHolderID="MainContent">
<h2>
WelcometoMasterOfComputerApplications
</h2>
<p>
FromtheDeskofDr.UshaJ.Professor&Director
TheDepartmentofMasterofComputerApplicationswasstartedintheyear1997.Thiscourseis
athreeyearPostGraduateprograminComputerApplications,affiliatedtoVisvesvaraya
TechnologicalUniversity(VTU),Belgaum,ApprovedbyAllIndiaCouncilforTechnicalEducation
81
R.V.College of Engineering
Dept. of MCA
(AICTE),NewDelhiandAccreditedbyNationalBoardofAccreditation(NBA)for3yearssince
September2013forthesecondtime.ThedepartmentofMCAatRVCEhasthecredential
achievementofbeingthefirstMCAprogramunderVTUtobeaccreditedbyNationalBoardof
Accreditation,NewDelhiduring2010.TheMilestonesofthedepartmentincluderecognitionas
VTUResearchCenter,increaseinintakeofthestudentsfrom60to120.Majoreventsinclude
fundedresearchprojects,IndustryInnovativelabsandopensourceconsultancyinComputer
Applications.TheVTUresearchcenterinthedepartmenthascurrently14Researchscholarsand
7researchguides.
</p>
</asp:Content>
<%@PageTitle="AboutUs"Language="C#"MasterPageFile="~/Site.master"
AutoEventWireup="true"
CodeFile="facility.aspx.cs"Inherits="About"%>
<asp:ContentID="HeaderContent"runat="server"ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:ContentID="BodyContent"runat="server"ContentPlaceHolderID="MainContent">
<h2>
About
</h2>
<p>
Putcontenthere.
82
R.V.College of Engineering
Dept. of MCA
</p>
</asp:Content>
<%@PageTitle=""Language="C#"MasterPageFile="~/Site.master"AutoEventWireup="true"
CodeFile="feedback.aspx.cs"Inherits="Default2"%>
<asp:ContentID="Content1"ContentPlaceHolderID="HeadContent"Runat="Server">
</asp:Content>
<asp:ContentID="Content2"ContentPlaceHolderID="MainContent"Runat="Server">
FeedBack
<table>
<tr>
<td>
Name
</td>
<td>
<asp:TextBoxID="name"runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Email
</td>
<td>
<asp:TextBoxID="email"runat="server"></asp:TextBox>
</td>
</tr>
<tr>
83
R.V.College of Engineering
Dept. of MCA
<td>
Message
</td>
<td>
<asp:TextBoxID="msg"runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:ButtonID="Button1"runat="server"Text="Cancel"/>
</td>
<td>
<asp:ButtonID="Button2"runat="server"Text="Submit"onclick="Button2_Click"/>
</td>
</tr>
</table>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
</asp:Content>
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data;
usingMySql.Data;
usingMySql.Data.MySqlClient;
publicpartialclassDefault2:System.Web.UI.Page
{
privatestringserver;
privatestringdatabase;
privatestringuid;
privatestringpassword;
privateMySqlConnectionconnection;
privateMySqlDataAdaptermySqlDataAdapter;
protectedvoidPage_Load(objectsender,EventArgse)
{
}
protectedvoidButton2_Click(objectsender,EventArgse)
{
server="localhost";
database="test1";
uid="root";
password="mca";
84
R.V.College of Engineering
Dept. of MCA
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+";"+
"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
stringquery="INSERTINTOfeedback1(name,email,msg)VALUES(?name,?email,?msg);";
MySqlCommandinsertCommand=newMySqlCommand(query,connection);
insertCommand.Parameters.AddWithValue("?name",name.Text);
insertCommand.Parameters.AddWithValue("?email",email.Text);
insertCommand.Parameters.AddWithValue("?msg",msg.Text);
try
{
connection.Open();
insertCommand.ExecuteNonQuery();
Label1.Text="inserted";
}
catch(Exceptionex)
{
Console.WriteLine("exception:"+ex);
}
connection.Close();
}
}
5.DevelopaWebApplicationusingC#.NETandASP.NETforaBank.TheBANKDatabase
shouldconsistoffollowingtables:tbl_Bank(BankID:int,BankName:string)tbl_Branch
(BranchID:int,BankID:int,BranchName:string)tbl_Account(AccountNo:int,BankID:int,
BranchID:int,CustomerName:string,Address:string,ContactNo:int,Balance:real)(Note:
AccountNoandBankIDtogetherisacompositeprimarykey).
ThemasterpageofthiswebapplicationshouldcontainhyperlinkstoNewBankEntry,New
BranchEntry(ofselectedBank),NewCustomerEntry(basedonbranchandbank)and
ReportGeneration.Thehyperlinksshouldnavigatetorespectivecontentpages.These
contentpagesprovidethefieldsforrespectivedataentry.Thereportsshouldbegenerated
(displayingrid)asbelow:
1.Displayallrecordsofparticularbank.
85
R.V.College of Engineering
Dept. of MCA
2.Displayallrecordsofabranchofparticularbank.
3.Thebalanceshouldbedisplayedfortheenteredaccountnumber(BankandBranch
areinputthroughComboBoxcontrolsandAccountnumberisinputthroughTextBox).
Fig5.1AddBank
<%@PageTitle=""Language="C#"MasterPageFile="~/Site.Master"AutoEventWireup="true"
CodeBehind="addBank.aspx.cs"Inherits="lab5.WebForm1"%>
<asp:ContentID="Content1"ContentPlaceHolderID="HeadContent"runat="server">
</asp:Content>
<asp:ContentID="Content2"ContentPlaceHolderID="MainContent"runat="server">
<br/>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
<br/>
AddNewBank
<table>
<tr>
<td>
BankID
</td>
<td>
<asp:TextBoxID="bankid"runat="server"></asp:TextBox>
</td>
</tr>
<tr>
86
R.V.College of Engineering
Dept. of MCA
<td>
BankName
</td>
<td>
<asp:TextBoxID="bankname"runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:ButtonID="Button1"runat="server"Text="cancel"/>
</td>
<td>
<asp:ButtonID="Button2"runat="server"Text="Save"onclick="Button2_Click"/>
</td>
</tr>
</table>
&nbs
p;
</asp:Content>
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data;
usingMySql.Data;
usingMySql.Data.MySqlClient;
namespacelab5
{
publicpartialclassWebForm1:System.Web.UI.Page
{
privatestringserver;
privatestringdatabase;
privatestringuid;
privatestringpassword;
privateMySqlConnectionconnection;
privateMySqlDataAdaptermySqlDataAdapter;
protectedvoidPage_Load(objectsender,EventArgse)
{
}
protectedvoidButton2_Click(objectsender,EventArgse)
{
server="localhost";
87
R.V.College of Engineering
Dept. of MCA
database="bank";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+";"+
"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
stringquery="INSERTINTOtbl_bank(bankid,bankname)VALUES(?bankid,?
bankname);";
MySqlCommandinsertCommand=newMySqlCommand(query,connection);
insertCommand.Parameters.AddWithValue("?bankid",bankid.Text);
insertCommand.Parameters.AddWithValue("?bankname",bankname.Text);
try
{
connection.Open();
insertCommand.ExecuteNonQuery();
Label1.Text="inserted";
}
catch(Exceptionex)
{
Console.WriteLine("exception:"+ex);
}
connection.Close();
}
}
}
88
R.V.College of Engineering
Dept. of MCA
Fig5.2AddBranch
<%@PageTitle=""Language="C#"MasterPageFile="~/Site.Master"AutoEventWireup="true"
CodeBehind="addBranch.aspx.cs"Inherits="lab5.WebForm2"%>
<asp:ContentID="Content1"ContentPlaceHolderID="HeadContent"runat="server">
</asp:Content>
<asp:ContentID="Content2"ContentPlaceHolderID="MainContent"runat="server">
<table>
<tr>
<td>
BranchId
</td>
<td>
<asp:TextBoxID="branchid"runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
BranchName
</td>
<td>
<asp:TextBoxID="branchname"runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
BankId
</td>
<td>
<asp:DropDownListID="bankid"runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:ButtonID="Button2"runat="server"Text="Cancel"/>
</td>
<td>
<asp:ButtonID="Button1"runat="server"Text="Save"onclick="Button1_Click"/>
</td>
</tr>
</table>
89
R.V.College of Engineering
Dept. of MCA
<p>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
</p>
</asp:Content>
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data;
//usingSystem.Data.SqlClient;
usingMySql.Data;
usingMySql.Data.MySqlClient;
namespacelab5
{
publicpartialclassWebForm2:System.Web.UI.Page
{
privatestringserver;
privatestringdatabase;
privatestringuid;
privatestringpassword;
privateMySqlConnectionconnection;
privateMySqlDataAdaptermySqlDataAdapter;
protectedvoidPage_Load(objectsender,EventArgse)
{
loaddrop();
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
server="localhost";
database="bank";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+";"+
"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
stringquery="INSERTINTOtbl_branch(branchid,branchname,bankid)VALUES(?
branchid,?branchname,?bankid);";
MySqlCommandinsertCommand=newMySqlCommand(query,connection);
insertCommand.Parameters.AddWithValue("?branchid",int.Parse(branchid.Text));
insertCommand.Parameters.AddWithValue("?branchname",branchname.Text);
insertCommand.Parameters.AddWithValue("?bankid",bankid.SelectedItem.Value);
90
R.V.College of Engineering
Dept. of MCA
try
{
connection.Open();
insertCommand.ExecuteNonQuery();
Label1.Text="inserted";
}
catch(Exceptionex)
{
Console.WriteLine("exception:"+ex);
}
connection.Close();
}
voidloaddrop()
{
server="localhost";
database="bank";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+";"+
"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
if(this.OpenConnection()==true)
{
mySqlDataAdapter=newMySqlDataAdapter("select*fromtbl_bank",connection);
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
bankid.DataTextField=DS.Tables[0].Columns["bankname"].ToString();
bankid.DataValueField=DS.Tables[0].Columns["bankid"].ToString();
bankid.DataSource=DS.Tables[0];
bankid.DataBind();
//closeconnection
this.CloseConnection();
}
}
privateboolOpenConnection()
{
try
{
connection.Open();
returntrue;
}
catch(MySqlExceptionex)
{
//Whenhandlingerrors,youcanyourapplication'sresponsebasedontheerror
number.
91
R.V.College of Engineering
Dept. of MCA
//Thetwomostcommonerrornumberswhenconnectingareasfollows:
//0:Cannotconnecttoserver.
//1045:Invalidusernameand/orpassword.
switch(ex.Number)
{
case0:
//MessageBox.Show("Cannotconnecttoserver.Contactadministrator");
break;
case1045:
//MessageBox.Show("Invalidusername/password,pleasetryagain");
break;
default:
//MessageBox.Show(ex.Message);
break;
}
returnfalse;
}
}
privateboolCloseConnection()
{
try
{
connection.Close();
returntrue;
}
catch(MySqlExceptionex)
{
//MessageBox.Show(ex.Message);
returnfalse;
}
}
}
}
92
R.V.College of Engineering
Dept. of MCA
Fig5.3AddAccount
<%@PageTitle=""Language="C#"MasterPageFile="~/Site.Master"AutoEventWireup="true"
CodeBehind="addAccount.aspx.cs"Inherits="lab5.WebForm3"%>
<asp:ContentID="Content1"ContentPlaceHolderID="HeadContent"runat="server">
</asp:Content>
<asp:ContentID="Content2"ContentPlaceHolderID="MainContent"runat="server">
<table>
<tr>
<td>
AccountNo
</td>
<td>
<asp:TextBoxID="accountno"runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
BankId
</td>
<td>
<asp:DropDownListID="bankid"runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
BranchId
</td>
93
R.V.College of Engineering
Dept. of MCA
<td>
<asp:DropDownListID="branchid"runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
CustomerName
</td>
<td>
<asp:TextBoxID="custname"runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Address
</td>
<td>
<asp:TextBoxID="address"runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
ContactNo
</td>
<td>
<asp:TextBoxID="contactno"runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
balance
</td>
<td>
<asp:TextBoxID="balance"runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:ButtonID="Button1"runat="server"Text="Cancel"/>
</td>
<td>
<asp:ButtonID="Button2"runat="server"Text="Save"onclick="Button2_Click"/>
</td>
</tr>
</table>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
94
R.V.College of Engineering
Dept. of MCA
</asp:Content>
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data;
usingMySql.Data;
usingMySql.Data.MySqlClient;
namespacelab5
{
publicpartialclassWebForm3:System.Web.UI.Page
{
privatestringserver;
privatestringdatabase;
privatestringuid;
privatestringpassword;
privateMySqlConnectionconnection;
privateMySqlDataAdaptermySqlDataAdapter;
protectedvoidPage_Load(objectsender,EventArgse)
{
loaddrop();
loaddrop1();
}
voidloaddrop()
{
server="localhost";
database="bank";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+";"+
"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
if(this.OpenConnection()==true)
{
mySqlDataAdapter=newMySqlDataAdapter("select*fromtbl_bank",connection);
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
bankid.DataTextField=DS.Tables[0].Columns["bankname"].ToString();
bankid.DataValueField=DS.Tables[0].Columns["bankid"].ToString();
bankid.DataSource=DS.Tables[0];
bankid.DataBind();
//closeconnection
95
R.V.College of Engineering
Dept. of MCA
this.CloseConnection();
}
}
voidloaddrop1()
{
server="localhost";
database="bank";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+";"+
"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
if(this.OpenConnection()==true)
{
mySqlDataAdapter=newMySqlDataAdapter("select*fromtbl_branch",connection);
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
branchid.DataTextField=DS.Tables[0].Columns["branchname"].ToString();
branchid.DataValueField=DS.Tables[0].Columns["branchid"].ToString();
branchid.DataSource=DS.Tables[0];
branchid.DataBind();
//closeconnection
this.CloseConnection();
}
}
privateboolOpenConnection()
{
try
{
connection.Open();
returntrue;
}
catch(MySqlExceptionex)
{
//Whenhandlingerrors,youcanyourapplication'sresponsebasedontheerror
number.
//Thetwomostcommonerrornumberswhenconnectingareasfollows:
//0:Cannotconnecttoserver.
//1045:Invalidusernameand/orpassword.
switch(ex.Number)
{
case0:
//MessageBox.Show("Cannotconnecttoserver.Contactadministrator");
break;
case1045:
96
R.V.College of Engineering
Dept. of MCA
//MessageBox.Show("Invalidusername/password,pleasetryagain");
break;
default:
//MessageBox.Show(ex.Message);
break;
}
returnfalse;
}
}
privateboolCloseConnection()
{
try
{
connection.Close();
returntrue;
}
catch(MySqlExceptionex)
{
//MessageBox.Show(ex.Message);
returnfalse;
}
}
protectedvoidButton2_Click(objectsender,EventArgse)
{
server="localhost";
database="bank";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+";"+
"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
stringquery="INSERTINTO
tbl_account(accountno,bankid,branchid,customername,address,contactbo,balance)VALUES(?
accountno,?bankid,?branchid,?customername,?address,?contactbo,?balance);";
MySqlCommandinsertCommand=newMySqlCommand(query,connection);
insertCommand.Parameters.AddWithValue("?accountno",int.Parse(accountno.Text));
insertCommand.Parameters.AddWithValue("?bankid",bankid.SelectedItem.Value);
insertCommand.Parameters.AddWithValue("?branchid",branchid.SelectedItem.Value);
insertCommand.Parameters.AddWithValue("?customername",custname.Text);
insertCommand.Parameters.AddWithValue("?address",address.Text);
insertCommand.Parameters.AddWithValue("?contactbo",contactno.Text);
insertCommand.Parameters.AddWithValue("?balance",balance.Text);
try
{
97
R.V.College of Engineering
Dept. of MCA
connection.Open();
insertCommand.ExecuteNonQuery();
Label1.Text="inserted";
}
catch(Exceptionex)
{
Console.WriteLine("exception:"+ex);
}
connection.Close();
}
}
}
Fig5.4Report
<%@PageTitle=""Language="C#"MasterPageFile="~/Site.Master"AutoEventWireup="true"
CodeBehind="report.aspx.cs"Inherits="lab5.WebForm4"%>
<asp:ContentID="Content1"ContentPlaceHolderID="HeadContent"runat="server">
</asp:Content>
<asp:ContentID="Content2"ContentPlaceHolderID="MainContent"runat="server">
<table>
<tr>
<td>
DisplaybyBank:
<asp:DropDownListID="bank"runat="server">
</asp:DropDownList>
98
R.V.College of Engineering
Dept. of MCA
<asp:ButtonID="Button2"runat="server"Text="Search"onclick="Button2_Click"/>
</td>
<td>
Displaybybranch:<asp:DropDownListID="bracnh"runat="server">
</asp:DropDownList>
<asp:ButtonID="Button3"runat="server"Text="Search"onclick="Button3_Click"/>
</td>
<td>
Displaybyaccount:<asp:TextBoxID="TextBox1"
runat="server"></asp:TextBox><asp:Button
ID="Button1"runat="server"Text="Search"/>
</td>
</tr>
</table>
<p>
<asp:GridViewID="GridView1"runat="server">
</asp:GridView>
</p>
</asp:Content>
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data;
usingMySql.Data;
usingMySql.Data.MySqlClient;
namespacelab5
{
publicpartialclassWebForm4:System.Web.UI.Page
{
privatestringserver;
privatestringdatabase;
privatestringuid;
privatestringpassword;
privateMySqlConnectionconnection;
privateMySqlDataAdaptermySqlDataAdapter;
protectedvoidPage_Load(objectsender,EventArgse)
{
loaddrop();
}
voidloaddrop()
{
99
R.V.College of Engineering
Dept. of MCA
server="localhost";
database="bank";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+";"+
"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
if(this.OpenConnection()==true)
{
mySqlDataAdapter=newMySqlDataAdapter("select*fromtbl_bank",connection);
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
bank.DataTextField=DS.Tables[0].Columns["bankname"].ToString();
bank.DataValueField=DS.Tables[0].Columns["bankid"].ToString();
bank.DataSource=DS.Tables[0];
bank.DataBind();
//closeconnection
this.CloseConnection();
}
}
privateboolOpenConnection()
{
try
{
connection.Open();
returntrue;
}
catch(MySqlExceptionex)
{
//Whenhandlingerrors,youcanyourapplication'sresponsebasedontheerror
number.
//Thetwomostcommonerrornumberswhenconnectingareasfollows:
//0:Cannotconnecttoserver.
//1045:Invalidusernameand/orpassword.
switch(ex.Number)
{
case0:
//MessageBox.Show("Cannotconnecttoserver.Contactadministrator");
break;
case1045:
//MessageBox.Show("Invalidusername/password,pleasetryagain");
break;
default:
//MessageBox.Show(ex.Message);
break;
}
100
R.V.College of Engineering
Dept. of MCA
returnfalse;
}
}
privateboolCloseConnection()
{
try
{
connection.Close();
returntrue;
}
catch(MySqlExceptionex)
{
//MessageBox.Show(ex.Message);
returnfalse;
}
}
protectedvoidButton2_Click(objectsender,EventArgse)
{
server="localhost";
database="bank";
uid="root";
password="mca";
stringconnectionString;
connectionString="SERVER="+server+";"+"DATABASE="+database+";"+
"UID="+uid+";"+"PASSWORD="+password+";";
connection=newMySqlConnection(connectionString);
if(this.OpenConnection()==true)
{
mySqlDataAdapter=newMySqlDataAdapter("select*fromtbl_bankb,tbl_branch
bh,tbl_accountawhereb.bankid=bh.bankidandb.bankid=a.bankidandb.bankname='"+
bank.SelectedItem.Text+"'",connection);
DataSetDS=newDataSet();
mySqlDataAdapter.Fill(DS);
GridView1.DataSource=DS.Tables[0];
GridView1.DataBind();
//closeconnection
this.CloseConnection();
}
}
protectedvoidButton3_Click(objectsender,EventArgse)
{
}
}
}
101
R.V.College of Engineering
Dept. of MCA
Vivaquestions
102
R.V.College of Engineering
Dept. of MCA
VIVAQUESTIONS
Ques.
No.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
103
VivaQuestions
WhatisboxingandUnboxingfeatureinC#?
Statethedifferencebetweenvaluetypesandreferencetypes
Whatisanobject?
Whatisaclass?
Whatisanamespace?
ExplainsomeoftheimportantfeaturesofVisualstudio
ExplaintheanatomyofabasicC#class
Whatisaconstructoroverloading
Whatarethebasicinputandoutputconsoleclass?
Whatisreferencetype?Giveexamples
ListthedifferentiterationconstructsusedinC#
ListthedifferentcontrolflowconstructsusedinC#
Explainajaggedarray
Mentionthedifferencebetweentherectangulararrayandjaggedarray
Whatisthedifferencebetweenforloopandwhileloop?
Whatisenumeration?GiveExample
Whatisavaluetype?Giveexamples
Whatarethedifferentfunctionsofarrayobject?
Whatthedifferentfunctionandpropertiesofstringobject?
Whatisencapsulation
WhatisReadOnlyField
Explaincasting
Whatispolymorphism?Explainwithanexample
Whicharethe3pillarsofOOPs
Whatisanexception
Whatisdebugging?
Whatisanerror?
WhatarethedifferenttypesofExceptionsthrownin.Net
ExplainGarbagecollectionin.Net
ExplainthebaseclassSystem.Exception
WhatisthedifferencebetweenFinalandFinally
Whatisinterfaces?
Whatisthedifferencebetweenandinterfaceandabstractclass
ExplainIEnumeration
ExplainIConvertible
ExplainICloneable
ExplainIcomparable
Whatarethebuiltininterfaces
Whatisametadata?
Whatiscallbacks,giveexample
Describeoverloading
R.V.College of Engineering
42
43
44
45
46
47
48
49
50
Dept. of MCA
WhatisDelegate?
Whatisevents?
WhatarethedifferenttypesofDelegates?
Whatisindexers?
ExplaincheckedanduncheckedkeywordinC#
Whatisoperatoroverloading?
Whatisanarray?
GivefewStringmethodsandexplain
Explainforeachloop
ExtraPrograms
1. Writeaprogramtovalidatetheusernameandpassword.Givecorresponding
messages(ConnecttotheDBtovalidatetheusernameandpassword).
2. Writeaprogramtofindtheperimeter,areaofatriangle(when3sidesaregiven)
andsquareusingconceptsofvirtualandoverridemethodsinC#
3. Usewindowsformsanddesignaloginpage.Andimplementtheprg1.
104
R.V.College of Engineering
Dept. of MCA
.NetLabCycleFortheVsemester
SubjectCode:13MCA57 I.AMarks:50
Hours/Week:3
ExamHours:03
TotalHours:42
ExamMarks:50
CourseOutcomes(AsperBloomsRevisedtaxonomy)
1. ExplainC#andclientserverconceptsusing.NetFrameWork
Components.
2. Applydelegates,eventandexceptionhandlingtoincorporatewith
ASP,WinForm,ADO.NET.
3. Analyzetheuseof.NetComponentsdependingontheproblem
statement.
4. ImplementasuitableapproachtodevelopawebbasedandConsole
basedapplicationwithDatabaseconnectivity.
Nos
Lab
Cycle:1
Lab
Cycle:2
Lab
Cycle:3
WriteaPrograminC#todemonstratecommandLineargument.
WriteaPrograminC#todemonstrateBoxingandunBoxing
WriteaProgramtodemonstrateOperatoroverloading.
Findthesumofalltheelementspresentinajaggedarrayof3inner
arrays.
UsingTry,CatchandFinallyblockswriteaprograminC#to
demonstrateerrorhandling.
DemonstrateUseOfVirtualandoverridekeywordinC#withasimple
Program.
Writeaprogramtodemonstratedelegates.
Writeaprogramtodemonstrateabstractclassandabstractmethodsin
C#.
WriteaprogramtoillustratetheuseofdifferentpropertiesinC#
105
Programnumberwiththequestion
PartA
R.V.College of Engineering
10
Dept. of MCA
Demonstratearraysofinterfacetypes(forruntimepolymorphism)with
aC#program.
PartB
Lab
Cycle:4
CreatingDatabase,TableandDesigningForms
ConsidertheDatabaseSTUDENTconsistingoffollowingtables:
tbl_Course(CourseID:int,CourseName:string)tbl_Student(USN:
string,StudName:string,Address:string,CourseID:int,YrOfAdmsn:
int)
DevelopsuitablewindowsapplicationusingC#.NEThavingfollowing
options:
1.Enteringnewcoursedetails.
2.Enteringnewstudentdetails.
3.Displaythedetailsofstudents(inaGrid)whobelongtoaparticular
course.
4.Displaythedetailsthestudentswhohavetakenadmissionina
particularyear.
Lab
Cycle:5
ImplementingCodefortheaboveDesignspecification
ConsidertheDatabaseSTUDENTconsistingoffollowingtables:
tbl_Course(CourseID:int,CourseName:string)tbl_Student(USN:
string,StudName:string,Address:string,CourseID:int,YrOfAdmsn:
int)
Lab
Cycle:6
CreatingDatabase,TableandDesigningForms
ConsidertheDatabaseSTUDENTconsistingoffollowingtables:
ConsidertheDatabaseBLOODBANKconsistingoffollowingtables:
tbl_BloodGroup(BloodID:int,BloodGroup:string)tbl_Donor
(DonorID:int,DonorName:stirng,Address:string,ContactNo:int,DOB:
date,Gender:string,Weight:int,BloodID:int)
106
R.V.College of Engineering
Dept. of MCA
DevelopsuitablewindowsapplicationusingC#.NEThavingfollowing
options:
1.EnteringBloodgroupdetails.
2.Enteringnewdonordetails.
3.Displaythedetailsofdonors(inaGrid)havingparticularblood
group.
4.Displaythedetailsofdonors(inaGrid)basedongender.
5.Displaythedetailsofdonors(inaGrid)basedonage(above18),
weight(above45KG)and
Gender(userschoice).
Lab
Cycle:7
ImplementingCodefortheaboveDesignspecification
ConsidertheDatabaseSTUDENTconsistingoffollowingtables:
ConsidertheDatabaseBLOODBANKconsistingoffollowingtables:
tbl_BloodGroup(BloodID:int,BloodGroup:string)tbl_Donor
(DonorID:int,DonorName:stirng,Address:string,ContactNo:int,
DOB:date,Gender:string,Weight:int,BloodID:int)dcds,ds,s
Lab
Cycle:8
CreatingDatabase,TableandDesigningForms
ConsidertheDatabaseSTUDENTconsistingoffollowingtables:
tbl_Course(CourseID:int,CourseName:string)tbl_Book(BookID:int,
BookTitle:string,Author:string,CourseID:int)tbl_Student(USN:
string,StudName:string,CourseID:int)tbl_BookIssue(USN:string,
BookID:int,IssueDate:Date)
DevelopsuitablewindowsapplicationusingC#.NEThavingfollowing
options:
1.NewCourseEntry.
2.NewBookEntry
107
R.V.College of Engineering
Dept. of MCA
3.NewStudentEntry
4.Issueofbookstoastudent.
5.Generatereport(displayinagrid)showingallthebooksbelongingto
particularcourse.
6.Generatereport(displayinagrid)showingallthebooksissuedona
particulardate.
7.Generatereport(displayinagrid)showingallthebooksissuedtoa
particularstudent.
Lab
Cycle:9
ImplementingCodefortheaboveDesignspecification
ConsidertheDatabaseSTUDENTconsistingoffollowingtables:
tbl_Course(CourseID:int,CourseName:string)tbl_Book(BookID:int,
BookTitle:string,Author:string,CourseID:int)tbl_Student(USN:
string,StudName:string,CourseID:int)tbl_BookIssue(USN:string,
BookID:int,IssueDate:Date)
Lab
Cycle:
10
Lab
Cycle:
11
CreatingDatabase,TableandDesigningFormsandCode
DevelopaWebApplicationusingC#.NETandASP.NETforaneducational
institution.ThemasterpageshouldconsistofInstitutionName,Logoand
Address.Also,itshouldprovidehyperlinkstoDepartments,FacilitiesAvailable
andFeedback.Eachdepartmentpageandfacilitiespageshouldbedesignedas
staticpages.Thehyperlinksshouldnavigatetothesestaticpagesintheformof
ContentPagesassociatedwithMasterPagedesigned.TheFeedbackpage
shouldhavefieldstoenterName,EmailandMessagewithSubmitandCancel
Buttons.Databaseshouldbecreatedtostorethesethreedata.
5
DevelopaWebApplicationusingC#.NETandASP.NETforaBank.TheBANK
Databaseshouldconsistoffollowingtables:tbl_Bank(BankID:int,BankName:
string)tbl_Branch(BranchID:int,BankID:int,BranchName:string)
tbl_Account(AccountNo:int,BankID:int,BranchID:int,CustomerName:
string,Address:string,ContactNo:int,Balance:real)(Note:AccountNoand
BankIDtogetherisacompositeprimarykey).
ThemasterpageofthiswebapplicationshouldcontainhyperlinkstoNew
BankEntry,NewBranchEntry(ofselectedBank),NewCustomerEntry(based
onbranchandbank)andReportGeneration.Thehyperlinksshouldnavigateto
108
R.V.College of Engineering
Dept. of MCA
respectivecontentpages.Thesecontentpagesprovidethefieldsforrespective
dataentry.Thereportsshouldbegenerated(displayingrid)asbelow:
1.Displayallrecordsofparticularbank.
2.Displayallrecordsofabranchofparticularbank.
3.Thebalanceshouldbedisplayedfortheenteredaccountnumber(Bankand
Branch
areinputthroughComboBoxcontrolsandAccountnumberisinputthrough
TextBox).
Instructions:
Allottedprogramtobecompletedintheregularlabonly.
Anybacklogprogramtobecompletedafterfinishingregularlabprogram.
Procedureforwritingrecord:
LeftHandSide:
1
2
3
4
Theproblemstatementandashortdescriptionabout
thesyntaxusedintheprogram.
UsageofNamespacesusedintheprogram.
InputandOutput.
Application&Outcomeofthelabcycle.
RightHandSide:
1
Program.
Evaluationcriteriafor10marks:
Datasheetwriteup+viva2Marks
Execution
5Marks
Recordwitting
3Marks
109
R.V.College of Engineering
Dept. of MCA
PracticalExamination:
IntheexaminationeachstudenthastoexecuteonequestionfrompartA
andonequestionfrompartB..
InstructionsforLabStaffinchargeandCostaff
Labinchargesareresponsibleforoverallprogramcompletionandfollow
up
Labcofacultyshouldtakecareofrecordverificationandmarksupdating
theattendanceregister
(HarishGM)
(SandeepaPateelaGC)
Director
StaffInChargeStaffInCharge
ASection
BSectionDept.ofMCA
110
R.V.College of Engineering
Dept. of MCA
DosandDontsintheLaboratory
DO..
ComepreparedtotheLab.
SubmityourRecordstotheLecturerandsignintheLogBook
onenteringtheLab.
Follow the Lab cycles as instructed by the Department.
Violatingthesamewillresultindeductionofmarks.
Usethesamelogin(ifany)assignedtoyou.
Putthechairsbacktoitspositionbeforeyouleave.
Backlog exercises to be executed after completing regular
exercises.
Keepyourpremisesclean.
DONT..
Movearoundinthelabduringthelabsession.
TamperSystemFilesorTrytoaccesstheServer.
WriteDataSheetsorRecordsintheLab
Changethesystemassignedtoyouwithoutthenoticeofthe
LabStaff.
Writeonthetableormousepads.
Teachingyourfriendsduringlabsessions.
111