Vous êtes sur la page 1sur 40

DATA ACCESS LAYER:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DataAccessLayer
/// </summary>
public class DataAccessLayer
{
string constr;
public DataAccessLayer()
{
constr =
ConfigurationManager.ConnectionStrings["dbConstr"].ToString();
}
public SqlConnection openDBCOn()
{
SqlConnection con = new SqlConnection(constr);
con.Open();
return con;
}

public int exequery(string q)


{

SqlCommand cmd = new SqlCommand(q, openDBCOn());


if (cmd.ExecuteNonQuery() > 0)
return 1;
return -1;
}

public void fillDS(string q, GridView gv)


{
SqlDataAdapter da =
new SqlDataAdapter(q,openDBCOn());
DataSet ds = new DataSet();
da.Fill(ds);
gv.DataSource = ds.Tables[0];
gv.DataBind();
}
}
DROPDOWN MENU:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Menu.master.cs"
Inherits="Menu" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>
<asp:ContentPlaceHolder id="title" runat="server">

</asp:ContentPlaceHolder>
</title>
<style type="text/css">
ul
{
list-style-type:none;
margin:0;
padding:0;
overflow:hidden;
background-color:#333;
}

li
{
float:left;
}
li a, .dropbtn
{
display:inline-block;
color:White;
text-align:center;
padding:14px 16px;
text-decoration:none;
}

li a:hover, .dropbtn
{
background-color:#333;
display:block;
}

li.dropdown
{

display:inline-block;
}
.dropdown-content
{
display:none;
position: absolute;
background-color: Black;
min-width:160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
dropdown-content a
{
color:Black;
padding: 12px 16px;
text-decoration: none;
display:block;
text-align:center;
}

.dropdown-content a:hover
{
background-color:Red;
}
.dropdown:hover .dropdown-content
{
display:block;
}
ul.topnav li a.active
{
background-color:#4CAF50;
}

a.active
{
background-color:#4CAF50
}
li.right
{
float:right;
background-color:Red;
}

#copyright
{
background-color:Black;
color:White;
width:100%;
height:5%;
padding:1px;
margin-top:380px;
}

</style>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="#">Universities</a></li>
<li class="dropdown">
<a href="javascript:void(0)" class="dropbtn">Lectures</a>
<div class="dropdown-content">
<a href="#link1">Link 1</a><br />
<a href="#link2">Link 2</a><br />
<a href="#link3">Link 3</a><br />
<a href="#link4">Link 4</a><br />
</div>
</li>

<li class="dropdown">
<a href="javascript:void(0)" class="dropbtn">Courses</a>
<div class="dropdown-content">
<a href="#link1">Link 1</a><br />
<a href="#link2">Link 2</a><br />
<a href="#link3">Link 3</a><br />
<a href="#link4">Link 4</a><br />
</div>
</li>

<li class="right"> <a href="#about">About Us</a></li>

</ul>
<asp:ContentPlaceHolder id="body" runat="server">

</asp:ContentPlaceHolder>

<div id="copyright">
<h4>All Rights is reserved by Tech Origin @2018</h4>
</div>
</div>
</form>
</body>
</html>

VALIDATION CONTROLS:
<asp:TextBox ID="TextBox2" runat="server" type="text" name="user_name"
class="validate[required,custom[email]]" placeholder="Email Name
here..."></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox2" ErrorMessage="Name Must be Entered..."
SetFocusOnError="True"></asp:RequiredFieldValidator>
<br>
<asp:TextBox ID="TextBox3" runat="server" type="text" name="user_email"
class="validate[required]" placeholder="Enter Email Here..."></asp:TextBox><br>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Enter Valid Email Address..." ControlToValidate="TextBox3"
SetFocusOnError="True"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-
.]\w+)*"></asp:RegularExpressionValidator>
<asp:TextBox ID="TextBox4" runat="server" type="password" name="user_password"
class="validate[required]" placeholder="Enter Your password..."></asp:TextBox><br>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox4" ErrorMessage="Password Must be Entered..."
SetFocusOnError="True"></asp:RequiredFieldValidator>
<br>
<asp:TextBox ID="TextBox5" runat="server" type="text" name="user_age"
class="validate[required]" placeholder="Enter Your Age..."></asp:TextBox><br>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox5" ErrorMessage="Age Entered..."
SetFocusOnError="True"></asp:RequiredFieldValidator>
<br>
<asp:TextBox ID="TextBox6" runat="server" type="text" name="user_gender"
class="validate[required]" placeholder="Gender..."></asp:TextBox><br>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="TextBox6" ErrorMessage="Gender Must be Enter.."
SetFocusOnError="True"></asp:RequiredFieldValidator>
<br>
<asp:TextBox ID="TextBox7" runat="server" type="text" name="user_phone"
class="validate[required]" placeholder="Enter Phone Number..."></asp:TextBox><br>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="TextBox7" ErrorMessage="Contact Details Must Be Entered.."
SetFocusOnError="True"></asp:RequiredFieldValidator>
<br>
</form>
<div class="sign_in_bottom">
<asp:Button ID="Button1" runat="server" type="submit" OnClick="Button1_Click"
value="Sign Up" name="login_form" Text="Sign Up"></asp:Button ><br />
<asp:Label ID="lbmsg" runat="server" Text=""></asp:Label>
DATA INSERT WITH XML FILE:
<asp:TextBox ID="TextBox2" runat="server" type="text" name="user_name"
class="validate[required,custom[email]]" placeholder="Doctor Namer...">
</asp:TextBox><br />

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"


ControlToValidate="TextBox2" ErrorMessage="Name Must be Entered..."
SetFocusOnError="True"></asp:RequiredFieldValidator>

//Add Text Box


<asp:TextBox ID="TextBox3" runat="server" type="text" name="user_email"
class="validate[required]" placeholder="Doctor Email Here...">
</asp:TextBox><br>

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"


ErrorMessage="Enter Valid Email Address..." ControlToValidate="TextBox3"
SetFocusOnError="True"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpressionValidator>

//Add Text Box


<asp:TextBox ID="TextBox4" runat="server" type="text" name="user_password"
class="validate[required]" placeholder="Doctor Speciality...">
</asp:TextBox><br>

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"


ControlToValidate="TextBox4" ErrorMessage="Password Must be Entered..."
SetFocusOnError="True">
</asp:RequiredFieldValidator>

//Add Text Box


<asp:TextBox ID="TextBox5" runat="server" type="text" name="user_age"
class="validate[required]" placeholder="Contact Number...">
</asp:TextBox><br>

<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"


ControlToValidate="TextBox5" ErrorMessage="Age Entered..."
SetFocusOnError="True"></asp:RequiredFieldValidator>

//Add Text Box


<asp:TextBox ID="TextBox6" runat="server" type="text" name="user_gender"
class="validate[required]" placeholder="Doctor Time...">
</asp:TextBox><br>

<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"


ControlToValidate="TextBox6" ErrorMessage="Gender Must be Enter.."
SetFocusOnError="True">
</asp:RequiredFieldValidator>

//Add Text Box


<asp:TextBox ID="TextBox7" runat="server" type="text" name="user_phone"
class="validate[required]" placeholder="Address...">
</asp:TextBox><br>

<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"


ControlToValidate="TextBox7" ErrorMessage="Contact Details Must Be Entered.."
SetFocusOnError="True"></asp:RequiredFieldValidator>
</form>

//Add Button
<asp:Button ID="Button1" runat="server" type="submit"
OnClick="Button1_Click" value="Sign Up" Text="Add Doctor">
</asp:Button ><br />

//Add Text Box


<asp:Label ID="lbmsg" runat="server" Text=""></asp:Label>

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Xml;

public partial class DoctorList : System.Web.UI.Page


{
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
ds = new DataSet();
ds.ReadXml(Server.MapPath("DoctorList.xml"));
gvDoctor.DataSource = ds.Tables[0];
gvDoctor.DataBind();
}

protected void Button1_Click(object sender, EventArgs e)


{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("DoctorList.xml"));

XmlElement Doctor = xmldoc.CreateElement("Doctor");

XmlElement DocName = xmldoc.CreateElement("DocName");


DocName.InnerText = TextBox2.Text;

XmlElement DocEmail = xmldoc.CreateElement("DocEmail");


DocEmail.InnerText = TextBox3.Text;

XmlElement DocSpeciality = xmldoc.CreateElement("DocSpeciality");


DocSpeciality.InnerText = TextBox4.Text;

XmlElement Contact = xmldoc.CreateElement("Contact");


Contact.InnerText = TextBox5.Text;

XmlElement Timing = xmldoc.CreateElement("Timing");


Timing.InnerText = TextBox6.Text;

XmlElement Address = xmldoc.CreateElement("Address");


Address.InnerText = TextBox7.Text;
Doctor.AppendChild(DocName);
Doctor.AppendChild(DocEmail);
Doctor.AppendChild(DocSpeciality);
Doctor.AppendChild(Contact);
Doctor.AppendChild(Timing);
Doctor.AppendChild(Address);
xmldoc.DocumentElement.AppendChild(Doctor);
xmldoc.Save(Server.MapPath("DoctorList.xml"));

lbmsg.Text = "New Doctor Record Saved...";

TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";

}
}

<Doctor>
<DocName>Atif Saeed</DocName> <DocEmail>atifsaeedarts@gmail.com</DocEmail>
<DocSpeciality>Eye Specialist</DocSpeciality>
<Contact>03330333123</Contact>
<Timing>08-02</Timing>
<Address>Islamabad</Address>
</Doctor>
</DoctorList>

EMAIL WITH ATTACHMENT:


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

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

&lt;html xmlns="http://www.w3.org/1999/xhtml">
&lt;head runat="server">
&lt;title>&lt;/title>
&lt;style type="text/css">
.style1
{
width: 292px;
}
.style2
{
width: 213px;
}
.style3
{
width: 272px;
}
.style4
{
width: 213px;
height: 36px;
}
.style5
{
width: 272px;
height: 36px;
}
.style6
{
width: 292px;
height: 36px;
}
&lt;/style>
&lt;/head>
&lt;body>
&lt;form id="form1" runat="server">
&lt;table height=250px>
&lt;tr>
&lt;td colspan=3>&lt;h1>Welcome to Email Attachment Code&lt;/h1>&lt;/td>
&lt;/tr>

&lt;tr>
&lt;td class="style2">Email:&lt;/td>
&lt;td class="style3">
&lt;asp:TextBox ID="TextBox1" runat="server" Height="34px"
Width="208px">&lt;/asp:TextBox>
&lt;/td>
&lt;td class="style1">
&lt;asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="Email Must be Entered..."
SetFocusOnError="True"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-
.]\w+)*">&lt;/asp:RegularExpressionValidator>
&lt;/td>
&lt;/tr>

&lt;tr>
&lt;td class="style4">Subject:&lt;/td>
&lt;td class="style5">
&lt;asp:TextBox ID="TextBox3" runat="server" Height="34px"
Width="208px">&lt;/asp:TextBox>
&lt;/td>
&lt;td class="style6">&nbsp;&lt;/td>
&lt;/tr>

&lt;tr>
&lt;td class="style4">Attachment:&lt;/td>
&lt;td class="style5">
&lt;asp:FileUpload ID="FileUpload1" runat="server" Height="22px" />
&lt;/td>
&lt;td class="style6">&lt;/td>
&lt;/tr>

&lt;tr>
&lt;td class="style2">Message:&lt;/td>
&lt;td class="style3">
&lt;asp:TextBox ID="TextBox2" runat="server" Height="70px" TextMode="MultiLine"
Width="248px">&lt;/asp:TextBox>
&lt;/td>
&lt;td class="style1">&lt;/td>
&lt;/tr>

&lt;tr>
&lt;td colspan=2>

&lt;asp:Button ID="Button1" runat="server" Height="39px" Text="Send Email"


Width="130px" onclick="Button1_Click" />

&lt;/td>
&lt;td class="style1">
&lt;asp:Label ID="lbmsg" runat="server">&lt;/asp:Label>
&lt;/td>
&lt;/tr>

&lt;/table>

&lt;/form>
&lt;/body>
&lt;/html>

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;

public partial class _Default : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("Email Here...");
msg.To.Add(TextBox1.Text);
msg.Subject = TextBox3.Text;
msg.Body = TextBox2.Text;
msg.IsBodyHtml = true;

if (FileUpload1.HasFile)
{
msg.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream,
FileUpload1.FileName));
}

SmtpClient smt = new SmtpClient();


smt.Host = "smtp.gmail.com";
System.Net.NetworkCredential ntwd = new NetworkCredential();
ntwd.UserName = "Email Here..."; //Your Email ID
ntwd.Password = "Password Here..."; // Your Password
smt.UseDefaultCredentials = true;
smt.Credentials = ntwd;
smt.Port = 587;
smt.EnableSsl = true;
smt.Send(msg);
lbmsg.Text = "Email Was Sent Successfully...";
lbmsg.ForeColor = System.Drawing.Color.ForestGreen;

TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";

}
}
SEND EMAIL WITHOUT ATTACHMENT:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 410px;
}
.style2
{
width: 117px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table height=336px>
<tr>
<td class="style2">To:</td>
<td class="style1">
<asp:TextBox ID="to" runat="server" Width="336px"></asp:TextBox>
</td>
</tr>

<tr>
<td class="style2">From:</td>
<td class="style1">
<asp:TextBox ID="from" runat="server" Width="336px"></asp:TextBox>
</td>
</tr>

<tr>
<td class="style2">Subject:</td>
<td class="style1">
<asp:TextBox ID="subject" runat="server" Width="336px"></asp:TextBox>
</td>
</tr>

<tr>
<td class="style2">Message:</td>
<td class="style1">
<asp:TextBox ID="body" runat="server" Height="103px" TextMode="MultiLine"
Width="336px"></asp:TextBox>
</td>
</tr>

<tr>
<td colspan=2>
<asp:Button ID="send" runat="server" Text="Send" Width="122px"
onclick="send_Click" />
</td>
</tr>
<tr>
<td colspan=2>

<asp:Label ID="status" runat="server"></asp:Label>

</td>
</tr>

</table>

</form>
</body>
</html>

//Send Button Backend Coding

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;

public partial class contactusform : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void send_Click(object sender, EventArgs e)
{
try
{
MailMessage message = new MailMessage(from.Text, to.Text, subject.Text, body.Text);
message.IsBodyHtml = true;

SmtpClient client = new SmtpClient("smtp.gmail.com", 587);


client.EnableSsl = true;

client.Credentials = new System.Net.NetworkCredential("atifsaeedarts@gmail.com",


"Password Here...");
client.Send(message);

status.Text = "Mail was send Successfully...!";

from.Text = "";
to.Text = "";
subject.Text = "";
body.Text = "";
}

catch (Exception ex)


{
status.Text = ex.StackTrace;
Q44
<connectionStrings>
<add name="cs" connectionString="Data Source = (local); Initial Catalog= MIT; Integrated
Security= true;" />
</connectionStrings>
Q46
Design:
<form id="form1" runat="server">
<div>
<asp:RadioButton id="rBtn1" GroupName="Fruits"
Text="Apple" runat="server"/>
<asp:RadioButton id="rBtn2" GroupName="Fruits"
Text="Orange" runat="server"/>
<asp:RadioButton id="rBtn3" GroupName="Fruits"
Text="ringo" runat="server"/>
<asp:RadioButton id="rBtn4" GroupName="Fruits"
Text="mango" runat="server"/>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
code:
protected void Button1_Click(object sender, EventArgs e)
{
if(rBtn1.Checked)
{
Response.Write("selected"+rBtn1.Text);
}
else if (rBtn2.Checked)
{
Response.Write("selected" + rBtn2.Text);
}
else if (rBtn3.Checked)
{
Response.Write("selected" + rBtn3.Text);
}
else if (rBtn4.Checked)
{
Response.Write("selected" + rBtn4.Text);
}
}
Q47
<marquee> some text </marquee>

Q50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Configuration;

public partial class login : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btn_login_Click(object sender, EventArgs e)
{

string con = @"Data Source = (local); Initial Catalog= logon; Integrated Security= true;";
SqlConnection myDB = new SqlConnection(con);
myDB.Open();

Connection string using web config and class:


Config code:
<connectionStrings>
<add name="cs" connectionString="Data Source = (local); Initial Catalog= MIT; Integrated
Security= true;" />
</connectionStrings>
Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for dataaccesslayer
/// </summary>
public class dataaccesslayer
{
string constr;
SqlConnection mydbcon;
public dataaccesslayer()
{
constr = System.Configuration.ConfigurationManager.ConnectionStrings["cs"].ToString();
}

public SqlConnection opendbcon()


{
mydbcon = new SqlConnection(constr);
mydbcon.Open();
return mydbcon;
}
//rest of code
Access object:
protected void Button1_Click(object sender, EventArgs e)
{
dataaccesslayer obj = new dataaccesslayer();
obj.opendbcon();
//rest of code
Q57
design:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
code:
protected void Button1_Click(object sender, EventArgs e)
{
string con = @"Data Source = (local); Initial Catalog= country; Integrated Security= true;";
SqlConnection myDB = new SqlConnection(con);
myDB.Open();
string q = "select country from kuni where srno= 1 ";
SqlDataAdapter da;
da = new SqlDataAdapter(q, con);
DataSet dsEmployees;
dsEmployees = new DataSet();
da.Fill(dsEmployees);
TextBox1.Text = dsEmployees.Tables[0].Rows[0][0].ToString();
}
Q63
Config code:
<connectionStrings>
<add name="cs" connectionString="Data Source = (local); Initial Catalog= MIT; Integrated
Security= true;" />
</connectionStrings>
Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for dataaccesslayer
/// </summary>
public class dataaccesslayer
{
string constr;
SqlConnection mydbcon;
SqlDataAdapter da;
DataSet ds;

public dataaccesslayer()
{
constr = System.Configuration.ConfigurationManager.ConnectionStrings["cs"].ToString();
}
public SqlConnection opendbcon()
{
mydbcon = new SqlConnection(constr);
mydbcon.Open();
return mydbcon;
}
public DataSet fillds(string query)
{
da = new SqlDataAdapter(query, opendbcon());
ds = new DataSet();
da.Fill(ds);
return ds;

public void filldg (GridView g, string query)


{
g.DataSource = fillds(query).Tables[0];
g.DataBind();
}
design:
<asp:GridView ID="GridView1" runat="server" CssClass="auto-style3"
Width="492px"></asp:GridView>
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class result_prereq : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

protected void go_Click(object sender, EventArgs e)


{

dataaccesslayer obj1 = new dataaccesslayer();


obj1.filldg(GridView1, "Select * from passfail where regid ='" + regid.Text + "'");

Q64
Query:
CREATE VIEW v1 AS
SELECT country
FROM kuni
WHERE srno= 1;
Design:
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
Code:
protected void Button1_Click(object sender, EventArgs e)
{
string con = @"Data Source = (local); Initial Catalog= country; Integrated Security= true;";
SqlConnection myDB = new SqlConnection(con);
myDB.Open();
string q = "select * from v1 ";
SqlDataAdapter da;
da = new SqlDataAdapter(q, con);
DataSet ds;
ds = new DataSet();
da.Fill(ds);

GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();

}
Q65

config file same as above


data access class functions same as above
class function for dropdown:

public void FillDD(DropDownList dd, string query)


{
dd.DataSource = fillds(query).Tables[0];
dd.DataValueField = ds.Tables[0].Columns[0].ToString();
dd.DataTextField = ds.Tables[0].Columns[1].ToString();
dd.DataBind();
}

Design:
<asp:DropDownList ID="DropDownList1" runat="server"
Height="52px" Width="249px" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>

code:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
dataaccesslayer obj = new dataaccesslayer();
obj.FillDD(DropDownList1, "select * from tblDepartment");
}
}

Q66

USE [country]
GO
/****** Object: StoredProcedure [dbo].[pro] Script Date: 02/07/2019 15:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[pro]
(
@srno int,
@country varchar(50),
@StatementType nvarchar(20) = ''
)
AS
BEGIN
IF @StatementType = 'Insert'
BEGIN
insert into kuni (country) values( @country)
END
IF @StatementType = 'Select'
BEGIN
select * from kuni
END
IF @StatementType = 'Update'
BEGIN
UPDATE kuni SET
country = @country
WHERE srno = @srno
END
else IF @StatementType = 'Delete'
BEGIN
DELETE FROM kuni WHERE srno = @srno
END
end

Q69

Q75
webservice:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{

public WebService()
{

[WebMethod]
public int add(int x, int y)
{
int z;
z = x + y;
return z;
}
}

Design:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>

code:

protected void Button1_Click(object sender, EventArgs e)


{
localhost.WebService obj = new localhost.WebService();
int n = Convert.ToInt32(TextBox1.Text);
int m = Convert.ToInt32(TextBox2.Text);
int res = obj.add(m, n);
Response.Write(res);
}
Q76

design:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>

code:
protected void Button1_Click(object sender, EventArgs e)
{
string con = @"Data Source = (local); Initial Catalog= country; Integrated Security= true;";
SqlConnection myDB = new SqlConnection(con);
myDB.Open();

string save = "insert into kuni values ('" + TextBox1.Text + "')";


SqlCommand cmd = new SqlCommand(save, myDB);
if (cmd.ExecuteNonQuery() > 0)
{
Response.Write("sucess");
}
else
{
Response.Write("error");
}
}

Q80
xml:

<?xml version="1.0" encoding="utf-8" ?>


<class>
<srno>
1
</srno>
<room>
cl1
</room>

<srno>
2
</srno>
<room>
cl2
</room>

<srno>
2
</srno>
<room>
cl3
</room>
</class>
design:
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
code:
using previous class webconfig...

public partial class xmlwebpage : System.Web.UI.Page


{
DataSet ds;

protected void Page_Load(object sender, EventArgs e)


{

ds = new DataSet();
ds.ReadXml(Server.MapPath("XMLFile.xml"));

GridView1.DataSource = ds.Tables[1];

GridView1.DataBind();

}
}

Vous aimerez peut-être aussi