Professional Documents
Culture Documents
NET 1BM19MCA16
Part-B
1. Build an application using Windows Programming and Database connectivity with
ADO.NET.
Code:
using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace CRUD_ADO_
{
public partial class Form1 : Form
{
public static SqlConnection? conn;
public Form1()
{
InitializeComponent();
}
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
catch (Exception ex)
{
MessageBox.Show(ex+"");
}
cmd.ExecuteNonQuery();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
catch (Exception x)
{
}
}
cmd.ExecuteNonQuery();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
catch (Exception x)
{
}
}
cmd.ExecuteNonQuery();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
catch (Exception x)
{
}
}
Output-
UI-
Database-
2. Build an application using ASP.NET techniques with appropriate validations and Database
connectivity with ADO.NET
Code:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Part2
{
public partial class WebForm1 : System.Web.UI.Page
{
public static SqlConnection conn;
protected void Page_Load(object sender, EventArgs e)
{
string Source ="server =.; Initial Catalog = Student; Integrated Security = True ";
conn = new SqlConnection(Source);
conn.Open();
}
}
public void Messagebox(string xMessage)
{
Response.Write("<script>alert('" + xMessage + "')</script>");
}
}
}
Design code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="Part2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 399px">
<asp:Label ID="Label1" runat="server" Text="First Name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" style="margin-left: 84px" Width="339px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="First Name Cant be Blank" Display="Dynamic" ForeColor="Red"
SetFocusOnError="True"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Last Name"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" style="margin-left: 86px" Width="339px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2"
ErrorMessage="Last Name Cant be Blank" ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<br />
Age &n
bsp;
<asp:TextBox ID="TextBox3" runat="server" Width="331px"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox3"
ErrorMessage="Age should be between 18 to 60" ForeColor="Red" MaximumValue="60"
MinimumValue="18"></asp:RangeValidator>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Email"></asp:Label>
<asp:TextBox ID="TextBox4" runat="server" Width="342px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox4"
ErrorMessage="Email cant be Empty" ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Label ID="Label4" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="TextBox5" runat="server" Width="338px" TextMode="Password"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label5" runat="server" Text="Confirm Password"></asp:Label>
<asp:TextBox ID="TextBox6" runat="server" style="margin-left: 21px" Width="330px"
TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBox5"
ControlToValidate="TextBox6" ErrorMessage="Password doesnt Match"
ForeColor="Red"></asp:CompareValidator>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" Height="50px" Text="Submit" Width="181px"
OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
OUTPUT:
DataBase:
1
BMS COLLEGE OF ENGINEERING BANGALORE
0