BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

VB.NET

1.Develop an application which is similar to notepad using menus.

Code:

1. Create a new Window application with name as notepad 2. Add Menu Strip to form1 and set IsMdiContainer property of form1 to true 3. Set text property of form1 as Notepad 4. Create File menu by adding text at type here textbox.(File,New ,Open,save,Exit) 5. Create Edit menu by adding text at type here textbox.(Edit,cut,Copy,Paste,Select All,Time/date,Clear) 6. Create Format menu by adding text at type here textbox.(Format,font) 7. Add Form2 tp project by clicking Project menu. 8. Add Richtextbox to form2 and set dock property of richtextbox to fill. 9. Add the following code by double clicking File-New Option in menustrip. 10. Add OpenfileDialog,SaveFileDialog,FontDialog to form1.

Public Class Form1

Dim n As Integer

Dim forms(10) As Form2

Dim s As String

Dim s1 As Integer

Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click

n += 1

forms(n) = New Form2

forms(n).Text = "Unititled document" & Str(n)

1 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA forms(n).MdiParent = Me

forms(n).Show()

End Sub

////// Double click on File-Open option in menu Strip and add the code.

Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click

OpenFileDialog1.Filter = "txtfile(*.txt*)|*.txt*"

If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

forms(n).Show()

forms(n).RichTextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)

forms(n).Text = OpenFileDialog1.FileName

End If

End Sub

////// Double click on File-Save option in menu Strip and add the code.

Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click

s = forms(n).RichTextBox1.Text

SaveFileDialog1.Filter = "txtfiles(*.txt*)|*.txt*"

SaveFileDialog1.Title = "save "

If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, s, True)

forms(n).Text = SaveFileDialog1.FileName

forms(n).RichTextBox1.Text = s

End If

End Sub

////// Double click on File-Close option in menu Strip and add the code.

2 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click

End

End Sub

////// Double click on Edit-Cut option in menu Strip and add the code.

Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripMenuItem.Click

forms(n).RichTextBox1.Select()

forms(n).RichTextBox1.Cut()

End Sub

////// Double click on Edit-Copy option in menu Strip and add the code.

Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripMenuItem.Click

forms(n).RichTextBox1.Select()

forms(n).RichTextBox1.Copy()

End Sub

////// Double click on Edit-Paste option in menu Strip and add the code.

Private Sub PasteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripMenuItem.Click

forms(n).RichTextBox1.Paste()

End Sub

////// Double click on Edit-SelectAll option in menu Strip and add the code.

Private Sub SelectAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectAllToolStripMenuItem.Click

forms(n).RichTextBox1.SelectAll()

3 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA End Sub

////// Double click on Edit-Clear option in menu Strip and add the code.

Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click

forms(n).RichTextBox1.Clear()

End Sub

////// Double click on Edit-Time/Date option in menu Strip and add the code.

Private Sub TimedateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimedateToolStripMenuItem.Click

forms(n).RichTextBox1.Text = Date.Today.ToString

End Sub

////// Double click on Format-Font option in menu Strip and add the code.

Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click

If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

forms(n).RichTextBox1.ForeColor = FontDialog1.Color

forms(n).RichTextBox1.Font = FontDialog1.Font

End If

End Sub

End Class

4 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA Design:

Title of the : Notepad Controls used:

Control Name Caption Form1 Notepad Form2 Form2 MenuStrip Menustrip1 OpenFileDialog OpenFileDialog1 SaveFileDialog SaveFileDialog1 FontDialog FontDialog1 Richtextbox1 Richtextbox1

2.a) Develop an application for facilitating purchasing order .

5 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

Code:

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

cmb_cars.Items.Add("car1")

cmb_cars.Items.Add("car2")

cmb_cars.Items.Add("car3")

cmb_cars.Text = "Select One"

End Sub

Private Sub cmb_cars_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmb_cars.SelectedIndexChanged

lst_model.Items.Clear()

txt_price.Clear()

cmb_colors.Items.Clear()

cmb_colors.Text = "select One"

Dim str As String = cmb_cars.SelectedItem.ToString()

MsgBox(str)

If str = "car1" Then

cmb_colors.Items.Add("red")

cmb_colors.Items.Add("blue")

cmb_colors.Items.Add("Black")

lst_model.Items.Add("Model1")

lst_model.Items.Add("Model2")

lst_model.Items.Add("Model3")

ElseIf cmb_cars.SelectedItem.ToString() = "car2" Then

6 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA cmb_colors.Items.Add("White")

cmb_colors.Items.Add("Silver")

cmb_colors.Items.Add("Black")

lst_model.Items.Add("Model4")

lst_model.Items.Add("Model5")

lst_model.Items.Add("Model6")

ElseIf cmb_cars.SelectedItem.ToString() = "car3" Then

cmb_colors.Items.Add("Darkgreen")

cmb_colors.Items.Add("green")

cmb_colors.Items.Add("Black")

lst_model.Items.Add("Model7")

lst_model.Items.Add("Model8")

lst_model.Items.Add("Model9")

End If

End Sub

Private Sub lst_model_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lst_model.SelectedIndexChanged

Dim str As String = lst_model.SelectedItem.ToString()

If str = "Model1" Or str = "Model4" Or str = "Model7" Then

txt_price.Text = "4,00000"

ElseIf str = "Model2" Or str = "Model5" Or str = "Model8" Then

txt_price.Text = "3,50000"

ElseIf str = "Model3" Or str = "Model6" Or str = "Model9" Then

txt_price.Text = "6,00000"

End If

End Sub

7 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA Private Sub btn_purchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_purchase.Click

MessageBox.Show("Thank for purchasing" & Cmb_cars.SelectedItem.ToString())

End Sub

End Class

Design:

Title of the form: Purchase Car

Controls used:

Control Name Text Form1 form1 Purchase car Label1 lbl_title Purchase car Label2 lbl_cars Cars Label3 lbl_colors Colors Label4 lbl_model Model Label5 lbl_price Price in Rs Button1 btn_purchase Purchase Button2 btn_cancel Cancel Combobox1 cmb_cars Select one Combobox2 cmb_colors Select One List box lst_model Textbox1 txt_price

b). Develop an application for billing system in coffee shop

8 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

Code:

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

lbl_cardno.Visible = False

txt_card.Visible = False

End Sub

Private Sub btn_calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_calculate.Click

Dim ws, wos, cc, hc, tc, tt, tot As Integer

ws = 5

wos = 8

cc = 20

hc = 10

If chk_tea.Checked = True Then

tt = txt_tea.Text * wos

ElseIf chk_tea.Checked = False Then

tt = txt_tea.Text * ws

End If 9 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA If chk_coffee.Checked = True Then

tc = txt_coffee.Text * cc

ElseIf chk_coffee.Checked = False Then

tc = txt_coffee.Text * hc

End If

tot = tt + tc

If rdo_cash.Checked = True Then

txt_amt.Text = tot

MsgBox("Payment received in Cash!Thank U u select" & chk_tea.Text & "and " & chk_coffee.Text)

ElseIf rdo_card.Checked = True Then

If txt_card.Text = "" Then

MsgBox("U must enter pin number")

txt_card.Focus()

Else

txt_card.Text = tot

MsgBox("Payment is deduced from ur account")

End If

ElseIf rdo_cash.Checked = False And Rdo_card.Checked = False Then

MsgBox("U must choose payment mode")

End If

End Sub

Private Sub rdo_card_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdo_card.CheckedChanged

lbl_cardno.Visible = True

txt_card.Visible = True

10 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA End Sub

Private Sub btn_close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_close.Click

Me.Close()

End Sub

End Class

Design:

Title of the form: Cafeteria

Controls used:

Control Name Text Form1 Form1 Cafeteria Label1 lbl_tea Tea Label2 lbl_coffee Coffee Label3 lbl_total Total amount in RS Label4 lbl_cardno Enter card No Label5 lbl_qty Qty Button1 btn_calculate Calculate Button2 btn_close Close Textbox1 txt_tea Textbox2 txt_coffee Textbox3 txt_amt Textbox4 txt_card Check box1 chk_tea Without sugar CheckBox2 chk_coffee Cold coffee Radio Button1 rdo_cash Cash RadioButtton2 rdo_card Crdit card GroupBox1 GroupBox2

11 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

3.a) Develop an application which is similar to login form.

Code:

Public Class Form1

Private Sub btn_login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_login.Click

If txt_user.Text = "sss” Then

If txt_pwd.Text = "sss" Then

Form2.Visible = True

Form2.Label1.Text = "successfully login"

Else

txt_pwd.Clear()

Form2.Visible = True

12 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA Form2.Label1.Text = "invalid password"

End If

Else

txt_user.Clear()

Form2.Visible = True

Form2.Label1.Text = "invalid username "

End If

Form2.Visible = True

Dim x As Integer

ProgressBar1.Value = 1

ProgressBar1.Maximum = 10000

ProgressBar1.Step = 1

For x = 1 To 10000

ProgressBar1.PerformStep()

Next x

Form2.PictureBox1.Image = Image.FromFile(":\Documents and Settings\general\My Documents\My Pictures\moon.bmp")

End Sub

Private Sub btn_cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_cancel.Click

Me.Close()

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Form2.Label1.Visible = True

End Sub

End Class 13 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA Design:

Title of the form:Login Form

Controls used:

Control Name Text Form1 Form1 Login Form Label1 lbl_User Username Label2 lbl_pwd Password Button1 btn_login Login Button2 btn_cancel Cancel Textbox1 txt_user Textbox2 txt_pwd ProgressBar1 Form2 Form2 Picture Box1 Picture Box1

b) Develop an application for fruits billing.

14 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

Code:

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

lbl_text.Visible = False

End Sub

Private Sub Txt_qty_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Txt_qty.KeyUp

If e.KeyCode >= "65" And e.KeyCode <= "90" Or e.KeyCode = 16 Then

MsgBox("Enter only numbers")

txt_qty.Clear()

txt_qty.Focus()

End If

End Sub

Private Sub txt_price_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txt_price.KeyUp

If e.KeyCode >= "65" And e.KeyCode <= "90" Or e.KeyCode = 16 Then

MsgBox("Enter only numbers")

txt_price.Clear()

txt_price.Focus()

End If

End Sub

Private Sub btn_calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_calculate.Click

lbl_text.Visible = True

lbl_text.Text = "The total cost is:" & txt_qty.Text * txt_price.Text

15 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA End Sub

End Class

Design:

Title of the form:Fruit Billing

Controls used:

Control Name Text Form1 Form1 Fruit Billing Label1 lbl_qty Quantity Label2 lbl_price Price Label3 lbl_text Login Button1 btn_calculate Calculate Button2 btn_Cancel Cancel Radio Button1 rdo_apple Apple Radio Button2 rdo_mango Mango Radio Button3 rdo_grapes Grapes Group Box1

4.Develop an application using tree view control.

16 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA 1. Create a window application and named it as Tree View

2. Add Two labels and tree view control to form1

3. Set the text property of label1 as Select the formatting option and label2 as Welcome.

4. In the properties window click on ellipse button beside the nodes option. This will open a tree node Editor dialog box.

5. Click on Add Root Button.

6. Type the text options in the text property. This will set the text of the node to options.

7. Now select the option node and click on Add Child button to add child nodes to the parent node Options.

8. Now set the text property of node as Size and add another chilld Format

9. Now add child nodes to size and Format and click ok button.

10. Double click on tree view and add following code.

Public Class Form1

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

If (e.Node.Text = "Small") Then

lbl_text.Font = New Font(lbl_text.Font.Name, 10, lbl_text.Font.Style)

End If

If (e.Node.Text = "Large") Then

lbl_text.Font = New Font(lbl_text.Font.Name, 20, lbl_text.Font.Style)

End If

If (e.Node.Text = "Bold") Then

lbl_text.Font = New Font(lbl_text.Font.Name, 15, FontStyle.Bold)

End If

If (e.Node.Text = "Small") Then

lbl_text.Font = New Font(lbl_text.Font.Name, 15, FontStyle.Italic)

End If 17 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA End Sub

End Class

Design:

Title of the form: Tree View Control Controls used:

Control Name Caption Form1 Tree View Tree view Tree View1 Label1 Lbl_title Select the formatting option Label2 Lbl_text Welcome

5.a) Develop an application using font dialog control.

Code:

18 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA Public Class Form1

Private Sub btn_format_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_format.Click

FontDialog1.showColor = True

If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

rtxt_text.Font = FontDialog1.Font

rtxt_text.ForeColor = FontDialog1.Color

End If

End Sub

End Class

Design:

Title of the form:Font Dialog

Controls used:

Control Name Text Form1 Form1 Font Dailog Rich Textbox1 rtxt_text This is a font dialog Btn_format Btn_format Format Font Dialog Font Dialog1

b) Develop an application using color dialog control.

19 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

Code:

Public Class Form1

Private Sub btn_format_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_format.Click

If colorDialog1.ShowDialog() <> Windows.Forms.DialogResult.Cancel Then

rtxt_text.BackColor = ColorDialog1.Color

End If

End Sub

End Class

Design:

Title of the form: Color Dialog

Controls used:

Control Name Text Form1 Form1 Color Dialog Rich Textbox1 rtxt_text This is a color dialog Btn_format Btn_format Format Color Dialog1 Color Dialog1

20 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

6.Develop an application to display the file selected by the user in a web browser control.

Code:

Public Class Form1 Private Sub btn_add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_add.Click If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then lst_items.Items.Add(OpenFileDialog1.FileName) End If End Sub

Private Sub btn_load_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_load.Click Dim s As String s = lst_items.SelectedItem MsgBox(s) WebBrowser1.Navigate(s) End Sub

21 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA Private Sub btn_scroll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_scroll.Click WebBrowser1.ScrollBarsEnabled = True

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load WebBrowser1.ScrollBarsEnabled = False

End Sub End Class

Design:

Title of the form: Web Browser Control

Controls used:

Control Name Text Form1 Form1 Web Browser List Box1 lst_items Button1 btn_add Add Items to list Button2 btn_load Load Files Button3 btn_scroll Show Scroll Bars Open FileDailog open File Dialog1 Web Browser Control Web Browser1

7. Develop an application using the data reader to read from a database.

22 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

Code:

Create a database and datasource name.

Creating a new data connection.

1. Create a new windows application and name it as databaseprogram. 2. Open explorer window which is present in view menu and then right click on data connections. 3. Select Add connection item. 4. This opens add connection window.click on change button. 5. Select Oracle database from the datasource and click on ok button. 6. Give the server name ,username and password and click on test connection button. 7. Click ok button. Adding and configuring data Adapter.

1.Add Oracle dataadapter control on form1 from data tab of toolbox.

2.Data adapter configuration wizard will open.

3.Click on new connection button and add anew data connection by following the steps under creating a new data connection.

4.Select the radiobutton beside ‘yes’ include sensitive data in the connection string option.

5.Click on next button.

6.Select radio button beside ‘Use sql statement option’.

7. Click on next button.

8.Click on Query builder button.

23 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA 9. Select the database in the add table window.

10.Click on add button to add data table in the query builder wndow.

11. Click on close button.

12.Click on the checkbox beside the ‘all columns option’ in the data table.

13. Click on ok button in the query builder window to add the sql statement in the dataadapter configuration wizard.

14.Click on finish button.

Creating a DataSet.

1.Click on ‘Generate DataSet’ option in data menu bar.

2.Generate Dataset window will open.Click on radio button beside ‘New’ option for creating a new dataset.

3.Click Ok button.

1. Drag and drop combobox control in the form. 2. Select the combobox and go to properties window and select datasource property. 3. Click the arrow to open the panel. It gives us access to the datasources. 4. Select the desired datasource. 5. After selection the panel will close and selected dataset name will be displayed as the value for the data source property. 6. Select display member property. Click the arrow to open the panel. The panel gives us to access the tables in the data set selected for the data source property. 7. Select the desired table. 8. Expand the table to display the fields in the table. Select the field whose value we want to display in the combo box. 9. Select value member property. Click the arrow to open the panel. The panel gives us to access the tables in the data set selected for the data source property. 10. Select the desired table. 11. Expand the table to display the fields in the table. Select the field whose value we want to retrieve from the combo box. 12. Double click on the combo box in the design mode and write the following code:

Public Class Form1

Private Sub cmb_id_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmb_id.SelectedIndexChanged

txt_fname.DataBindings.Clear()

24 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA txt_lname.DataBindings.Clear()

txt_city.DataBindings.Clear()

txt_phno.DataBindings.Clear()

txt_fname.DataBindings.Add("text", DataSet11, "author.firstname")

txt_lname.DataBindings.Add("text", DataSet11, "author.lastname")

txt_city.DataBindings.Add("text", DataSet11, "author.city")

txt_phno.DataBindings.Add("text", DataSet11, "author.phoneno")

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

OracleDataAdapter1.Fill(DataSet11, "author")

End Sub

End Class

Design:

Title of the form:Author database

Controls used:

Control Name Text Form1 Form1 Author Database Label1 Lbl_id Author id Label2 Lbl_fname First Name Label3 Lbl_lname Last Name Label4 Lbl_city City Label5 Lbl_phno Phone No Combobox1 Cmb_id Textbox1 txt_fname Textbox2 txt_lname Textbox3 txt_city Textbox4 txt_phno

25 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

26 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA ASP.NET

1.Design an application for dynamically populating a checkbox list.

Default.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

Untitled Page



                      

           

         Dotnet DAA MP DW & DM ES CNS PPL

27 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA CN OR WT AI

Default.aspx.vb

Partial Class _Default Inherits System.Web.UI.Page Protected Sub btn_submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_submit.Click lbl_t.Text = "you selected :
" For Each l As ListItem In CheckBoxList1.Items If l.Selected = True Then lbl_t.Text += l.Text + "
" End If Next End Sub End Class

Design:

Title of the form:Check box List

Controls used:

Control Name Text Button1 btn_submit Submit Lable1 lbl_t CheckboxList chk_list

28 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

2.Design an application for selecting a single day in the calendar control.

Default.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

Untitled Page 29 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA




            

Default.aspx.vb

Partial Class _Default

Inherits System.Web.UI.Page

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged

txt_name.Text = "You selected " + Calendar1.SelectedDate()

End Sub

End Class

Design:

Title of the form:Calendar

Controls used:

Control Name Text Calendar control Calendar1 Textbox1 txt_name

30 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

3.Design an application by using the new scroll bar feature with the panel server control.

Drag and drop panel control and add text.

Default.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

Untitled Page

31 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

 

Width="326px">

Hai

How ru

I am fine

sdfdffgfdgdfgfdhfghgf

fdgfhgfhgfhfg

fghfghgjhgjhg

ghjhgjghjhgjhg

hgjhgjhgjhgjhgj

hgjhgjhgjhgjhg

hgjhgjkgkjhkjh

Design:

Title of the form: Panel Server Control

Controls used:

Control Name Text Panel Panel1

32 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

4.Design an application with simple bulleted list control.

Drag and drop bulleted list control and add items.

Default.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

Untitled Page

33 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA




 

DAA

CNS

WT

Dotnet

Design:

Title of the form:Bulleted List Control

Controls used:

Control Name Text Bulleted List

34 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

5.Design an application for uploading files using the new file upload control.

Default.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

Untitled Page



35 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA









Default.aspx.vb.

Partial Class _Default

Inherits System.Web.UI.Page

Protected Sub Upload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Upload.Click

If FileUpload1.HasFile Then

Try

Label1.Text = "File Name: " & FileUpload1.PostedFile.FileName & "
" & "File Size:" & FileUpload1.PostedFile.ContentLength & "
" & " Content Type:" & FileUpload1.PostedFile.ContentType

Catch ex As Exception

Label1.Text = "Error: " & ex.Message.ToString

End Try

Else

Label1.Text = "you have not specified a file"

End If

End Sub

36 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA End Class

Design:

Title of the form:File Upload control

Controls used:

Control Name Text File Upload

6. Design an application for building a form in the wizard control.

37 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

Drag and drop a wizard control.

Default.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

Untitled Page



This is First step

 

This is second step

38 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA This is third and final step

 

  

Design:

Title of the form:Wizard Control

Controls used:

Control Name Text Wizard

7.Design an application by using the validation controls.

39 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

Untitled Page

ErrorMessage=" Must Enter ur name" Style="z-index: 102; left: 400px; position: absolute;top: 88px">

ErrorMessage="Must enter Your ID" Style="z-index: 103; left: 432px; position: absolute;top: 432px">

ErrorMessage="You must enter Ur Qualification" Style="z-index: 106; left: 398px;position: absolute; top: 149px">

ErrorMessage="Your age must be in the range 20-40" MaximumValue="40" MinimumValue="20" Style="z-index: 107; left: 88px; position: absolute; top: 272px" Type="Integer">

        

41 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

             

                  

     

MinimumValue="01-01-1961" Style="z-index: 117; left: 88px; position: absolute;top: 376px" Type="Date">

42 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

      

 

   







                       

                     


                   


ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Width="476px" ControlToValidate="TextBox5">

43 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

ControlToValidate="TextBox7" ErrorMessage="Password does not match">

Design:

Title of the form:Validation Controls

Controls used:

Control Name Text Label1 lbl_name Enter Ur name Label2 lbl_qual Qualification Label3 lbl_age Age Label4 lbl_dob Date Of Birth Label5 lbl_email Email Id Label6 lbl_Pwd Password Label7 lbl_pwd1 Reenter Password Label8 lbl_d DD-MM-YY RequiredField Validator required Field Validator1 RequiredField Validator required Field Validator2 RequiredField Validator required Field Validator3 RequiredField Validator required Field Validator4 RequiredField Validator required Field Validator5 RequiredField Validator required Field Validator6 RequiredField Validator required Field Validator7 Custome Validator custome Validator1 Compare Validator compare Validator1 RegularExpression Validator regularExpressionValidator1 RangeValidator range Validator1 Textbox1 txt_name Textbox2 txt_qual Textbox3 txt_age Textbox4 txt_dob Textbox5 txt_email Textbox6 txt_pwd

44 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA Textbox7 txt_pwd1 Button1 btn_submit Submit

8.Design an application using the images,sounds for error notification.

Default.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

45 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

Untitled Page


  





Design:

Title of the form:Error Notification

Controls used:

Control Name Text Label1 lbl_name Name TextBox1 txt_name Button1 btn_submit Submit Required Field Validator Required Field Validator1

46 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

9.Design an application using the grid view control in an ASP.Net web page.

1. Create a new Website and name it as Grid View.

2. Drag and drop GridView control to the default.aspx page .

3. Select Choose Data Source Option.

4. Configure the database and select the table that we want to display.

5. Run the application.

Default.aspx:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

47 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

Untitled Page

ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand='SELECT * FROM "AUTHOR"'>

48 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

Design:

Title of the form:Grid View

Controls used:

Control Name Text GridView GridView1

10.Design an application for adding an insert command to the sql data source control.

49 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

1. Create a new website and name it as Insert data

2. Open the server explorer window by clicking on view menu bar.Server explorer window will open.

3. Righr click on Data Connection option and choose add Connection .

4. Choose Oracle Database . Provide the server name, username and password.

5. Test the connection and click ok button.

6. Add Details View and Grid view to the default.aspx page.

7. Set the AutoGenerate Insert Button property of Details View to TRUE.

8. Click on choose Data Source option.

9. Select Database icon under where will the application get data from?

10. Click on Ok button. This open configure Data Source window.

11. Select the table that we want to display.

12. Write insert command query in source view of default.aspx page.

13. Run the application.

50 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA Default.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

Untitled Page



51 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

Design:

Title of the form:Insert data

Controls used:

Control Name Text GridView GridView1 Details View Details View1

11.Design a web site using the concept of master pages.

52 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

1. Create a new website and name it as Master Page.

2. Right Click on Solution Explorer and click Add new item option.

3. Select Master page option from templates tab.

4. Click on Add Button.

5. Now add the following code to masterpage.master.

Mastrpage.master

<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>

Untitled Page

53 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA My Company Homepage



Copyright 2009- My Company

6. Go to the solution explorer and right click to add a content page by using add New item.

7. Select web form option.

8. Click on Check box beside select master page option available at the bottom of add new item dialog box.

9. Now click on add button in add new item dialog box. Select a master page dialog box will appear.

10. Select master page.master option from contents of folder in selec a master page dialog box .click ok.

11. Now add following code to source file of default.aspx page.

Default.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" masterpagefile="~/MasterPage.master" Inherits="_Default" %>

12. Desing an application using themes.

55 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

1. Create a new website and name it as themes.

2. Right click in solution explorer and first select add asp.net folder option and the n click on Themes option.

3. This will add one folder named it as APP-Themes folder with one subfolder named as Theme1 inside it. Right clickon theme1 folder and select add new item option in solution explorer.

4. Select skin file option under the templates tab.

5. Click on Add button.

6. Now define the style properties of Theme.skin file by adding the following code in simple.skin file.

Simple.skin

7. similarly add another theme folder to app_thems and add skin file named it as Inverse .skin.

Inverse.skin

56 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

8. Now add following code for default.aspx page and run the application.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" Theme="Theme1" %>

Untitled Page

Select Theme
Simple Inverse




 










57 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

58 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA C#

1. Develop a project for performing arthimetic,relational and logical operators.

using System;

using System.Collections.Generic;

using System.Text;

namespace labsheet21

{

class Program

{

static void Main(string[] args)

{

int a, b,c;

Console.WriteLine("enter two number to perform airthematic operation");

Console.WriteLine("enter first number");

a = System.Convert.ToInt32(Console.ReadLine());

Console.WriteLine("enter second number");

b= System.Convert.ToInt32(Console.ReadLine());

c = a + b;

Console.WriteLine("addition is " +c);

c = a - b;

Console.WriteLine("substraction is " + c);

c = a * b;

Console.WriteLine("multiplication " + c);

c = a / b;

Console.WriteLine("division is " + c);

59 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA c=a % b;

Console.WriteLine("modulo division is " + c);

if (a==b)

Console.WriteLine("both number were equal ");

else if (a

Console.WriteLine("first one is least ");

else if (a>b)

Console.WriteLine("second oneis least " );

else

Console.WriteLine("not posible to apply relational operators ");

Console.WriteLine("logical operation among two numbers"); c = a & b;

Console.WriteLine(c);

c = a | b;

Console.WriteLine(c);

c = a ^ b;

Console.WriteLine(c);

if (a == 0 && b == 0)

Console.WriteLine("both were zeros");

else if (a == 0 || b == 0)

Console.WriteLine("one of the two is zero");

else

Console.WriteLine("both were non zeros");

Console.Read();

60 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

}

}

}

Output:

2. Develop a project for demonstrating polymorphism abstraction.

using System;

using System.Collections.Generic;

using System.Text;

namespace labsheet22

{

public class shape

{

public void area(int side)

{

61 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA int squarearea = side * side;

Console.WriteLine("the area of square is :" + squarearea);

}

public void area(int length, int breadth)

{

int rectanglearea = length * breadth;

Console.WriteLine("the area of rectangle is :" + rectanglearea);

}

class Program

{

static void Main(string[] args)

{

shape sh = new shape();

sh.area(15);

sh.area(10, 20);

Console.Write("\n" + "press enter to quit");

Console.ReadLine();

}

}

}

}

Output

62 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

3. Develop a project for demonstrating switch statements.

using System;

using System.Collections.Generic;

using System.Text;

namespace labsheet23

{

class Program

{

static void Main(string[] args)

{

int ch;

Console.WriteLine("enter ur choice");

ch = Int32.Parse(Console.ReadLine());

//Console.WriteLine("enter ur choice"+ch);

switch(ch)

63 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA {

case 1:Console.WriteLine ("u r enter 1");

break;

case 2:Console .WriteLine ("u r entered 2");

break;

case 3:Console .WriteLine ("u r entered 3");

break;

case 4:Console .WriteLine ("u r entered 4");

break;

case 5:Console .WriteLine ("u r entered 5");

break;

case 6:Console .WriteLine ("u r entered 6");

break;

case 7:Console .WriteLine ("u r entered 7");

break;

case 8:Console .WriteLine ("u r entered 8");

break;

case 9:Console .WriteLine ("u r entered 9");

break;

case 10:Console .WriteLine ("u r entered 10");

break;

default: Console.WriteLine("u r enterd greaterthan 10 value");

break;

64 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA }

Console.ReadLine ();

}

}

}

Output:

4. Develop a project for implementing inheritance using abstract classes.

using System;

using System.Collections.Generic;

using System.Text;

namespace labsheet22b

{

public class person

{

private int fage;

65 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA public person()

{

fage=21;

}

public virtual void setage(int age)

{

fage=age;

}

public virtual int getage()

{

return fage;

}

} public class adultperson:person

{

public adultperson()

{

}

public override void setage(int age)

{

if (age>21)

{

base.setage(age);

}

}

66 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA }

class Program

{

static void Main(string[] args)

{

person p=new person ();

p.setage(18);

adultperson ap = new adultperson();

ap.setage(18);

Console.WriteLine("person age:{0}", p.getage());

Console.WriteLine("adultperson age:{0}",ap.getage());

Console.ReadLine();

}

}

}

Output:

67 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

5. Develop a project for implementing interfaces using multiple inheritance.

using System;

using System.Collections.Generic;

using System.Text;

namespace multiplechashinheritance

{

interface baseinterface

{

void getdetails();

}

interface derivedinterface:baseinterface

{

void showdetails();

}

class interfaceimplementer : derivedinterface

{

private String name;

private int age;

private string address;

private long phonenumber;

public void getdetails()

{

Console.Write("enter your name");

68 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA name = Console.ReadLine();

Console.Write("enter your age");

age = int.Parse(Console.ReadLine());

Console.WriteLine("enter your adress");

address = Console.ReadLine();

Console.Write("enter your phone number;");

phonenumber = long.Parse(Console.ReadLine());

}

public void showdetails()

{

Console.WriteLine("");

Console.WriteLine("your details are");

Console.WriteLine("name:" + name);

Console.WriteLine("age:" + age);

Console.WriteLine("adress:" + address);

Console.WriteLine("phonenumber:" + phonenumber);

}

}

class Program

{

static void Main(string[] args)

{

interfaceimplementer myjob = new interfaceimplementer();

myjob.getdetails();

69 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA myjob.showdetails();

Console.ReadLine();

}

}

}

Output:

6. Create a form that is the main window of a program using window class.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

70 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA namespace WindowsApplication1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_MouseClick(object sender, MouseEventArgs e)

{

MessageBox.Show("this is a new window application");

}

}

}

Output:

71 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA 7. Create a form that is main window with button program.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace labsheet26

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void btn_add _Click(object sender, EventArgs e)

{

int a, c, b;

a = Int32.Parse (textBox1.Text);

b =Int32.Parse ( textBox2.Text);

c = a + b;

MessageBox.Show("additon is" + c);

72 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

}

private void btn_cancel _Click(object sender, EventArgs e)

{

this.Close();

}

}

}

Controls used:

Control Name Text Button1 btn_add Add Button2 btn_cancel Cancel Label1 lbl_a A Label2 lbl_b B

Output:

8. Create a form that is main window of a program using standard controls.

using System;

73 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;

namespace labshet27

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void btn_login_Click(object sender, EventArgs e)

{

if (textBox1.Text == "mca")

{

if (textBox2.Text == "mca")

{

label3.Text = "successfully login";

}

else

74 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA {

textBox2.Clear();

label3.Text = "invalid password";

}

}

else

{

textBox1.Clear();

label3.Text = "invalid username";

}

int x;

progressBar1.Value = 1;

progressBar1.Maximum = 10000;

progressBar1.Step = 1;

for( x=1;x<= 10000;x++)

{

progressBar1.PerformStep();

}

}

private void btn_cancel _Click(object sender, EventArgs e)

{

this.Close();

}

75 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA }

}

Controls used:

Control Name Text Label1 lbl_name Usern Name Label2 lbl_pwd Password Label3 lbl_text ProgressBar progress bar1 Button1 btn_login Login Button2 btn_cancel Cancel

Output:

9. Create a form which hdisplays the given inputs in the form of a tree view Structure.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

76 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA using System.Drawing; using System.Text; using System.Windows.Forms;

namespace treeviewcontrol

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)

{

if (e.Node.Text == "smaller")

{

label1.Font= new Font(label1.Font.Name, 7, label1.Font.Style);

}

if (e.Node.Text == "larger")

{

label1.Font = new Font(label1.Font.Name, 30, label1.Font.Style);

77 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA }

if (e.Node.Text == "bold") {

label1.Font = new Font(label1.Font.Name, (float)(label1.Font.Size), FontStyle.Bold);

}

if (e.Node.Text == "italic")

{

label1.Font = new Font(label1.Font.Name, (float)(label1.Font.Size), FontStyle.Italic);

}

}

private void Form1_Load(object sender, EventArgs e)

{

}

}

}

Output:

78 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA

10. Develop a project for implementing exception handling in c#.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace chashexception

{

public partial class Form1 : Form

79 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA {

public Form1()

{

InitializeComponent();

}

public void division(int x, int y)

{

string z;

try

{

x = x / y;

z = x.ToString();

MessageBox.Show(z);

}

catch (DivideByZeroException de)

{

MessageBox.Show("cannot divide by zero, this is a local error." + de.ToString());

}

finally

{

MessageBox.Show("the divisor program is closing,please click ok");

this.Close();

}

80 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA }

private void btn_ok _Click(object sender, EventArgs e)

{

int p, q;

p = int.Parse(textBox1.Text);

q = int.Parse(textBox2.Text);

division(p, q);

}

}

}

Controls used:

Control Name Text Label1 lbl_x X Label2 lbl_y Y Button1 btn_ok Ok

Output:

81 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA 11. Develop a project which displays the student infromation in the relevant fields from the database which laready exists.

Code:

Create a database and datasource name.

Creating a new data connection.

8. Create a new windows application and name it as databaseprogram. 9. Open server explorer window which is present in view menu and then right click on data connections. 10. Select Add connection item. 11. This opens add connection window.click on change button. 12. Select Oracle database from the datasource and click on ok button. 13. Give the server name ,username and password and click on test connection button. 14. Click ok button. Adding and configuring data Adapter.

1.Add Oracle dataadapter control on form1 from data tab of toolbox.

2.Data adapter configuration wizard will open.

3.Click on new connection button and add anew data connection by following the steps under creating a new data connection.

4.Select the radiobutton beside ‘yes’ include sensitive data in the connection string option.

5.Click on next button.

6.Select radio button beside ‘Use sql statement option’.

7. Click on next button.

82 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA 8.Click on Query builder button.

9. Select the database in the add table window.

10.Click on add button to add data table in the query builder wndow.

11. Click on close button.

12.Click on the checkbox beside the ‘all columns option’ in the data table.

13. Click on ok button in the query builder window to add the sql statement in the dataadapter configuration wizard.

14.Click on finish button.

Creating a DataSet.

1.Click on ‘Generate DataSet’ option in data menu bar.

2.Generate Dataset window will open.Click on radio button beside ‘New’ option for creating a new dataset.

3.Click Ok button.

13. Drag and drop combobox control in the form. 14. Select the combobox and go to properties window and select datasource property. 15. Click the arrow to open the panel. It gives us access to the datasources. 16. Select the desired datasource. 17. After selection the panel will close and selected dataset name will be displayed as the value for the data source property. 18. Select display member property. Click the arrow to open the panel. The panel gives us to access the tables in the data set selected for the data source property. 19. Select the desired table. 20. Expand the table to display the fields in the table. Select the field whose value we want to display in the combo box. 21. Select value member property. Click the arrow to open the panel. The panel gives us to access the tables in the data set selected for the data source property. 22. Select the desired table. 23. Expand the table to display the fields in the table. Select the field whose value we want to retrieve from the combo box. 24. Double click on the combo box in the design mode and write the following code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;

83 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA using System.Drawing; using System.Text; using System.Windows.Forms; namespace student { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

private void Form1_Load(object sender, EventArgs e) { oleDbDataAdapter1.Fill(dataSet11, "stu"); }

private void btn_first _Click(object sender, EventArgs e) {

this.BindingContext[dataSet11, "stu"].Position =0 ;

}

private void btn_next _Click(object sender, EventArgs e) { this.BindingContext[dataSet11, "stu"].Position += 1; }

private void btn_previous _Click(object sender, EventArgs e) { this.BindingContext[dataSet11, "stu"].Position -= 1; }

private void btn_last _Click(object sender, EventArgs e) { int n = dataSet11.stu.Count; this.BindingContext[dataSet11, "stu"].Position += n;

}

private void btn_cancel _Click(object sender, EventArgs e) { this.Close(); }

84 Dot Net Programming Lab Manual (MCA 506) BAPATLA ENGINEERING COLLEGE: BAPATLA Department of MCA } }

Controls used:

Control Name Text Label1 lbl_id Id Label2 lbl-name Name Label3 lbl_qual Qualification Label4 lbl_grade Grade Textbox1 txt_id Textbox2 txt_name Textbox3 txt_qual Textbox4 txt_grade Button1 btn_first First Button2 btn_next Next Button3 btn_previous Previous Button4 btn_last Last Button5 btn_cancel Cancel

85 Dot Net Programming Lab Manual (MCA 506)