0% found this document useful (0 votes)
52 views

Vasavi College of Engineering

This document contains code snippets and documentation for connecting to a database and performing operations using ASP.NET and C#. It includes code to connect to an Oracle database, insert data into a table, and retrieve data on button click events. It also includes code for a web service that adds two numbers and returns the result, and an example of calling the web service from an ASP.NET page. Finally, it contains code for a simple AJAX example to calculate the square of a number entered in a form.

Uploaded by

AdarshMadanala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Vasavi College of Engineering

This document contains code snippets and documentation for connecting to a database and performing operations using ASP.NET and C#. It includes code to connect to an Oracle database, insert data into a table, and retrieve data on button click events. It also includes code for a web service that adds two numbers and returns the result, and an example of calling the web service from an ASP.NET page. Finally, it contains code for a simple AJAX example to calculate the square of a number entered in a form.

Uploaded by

AdarshMadanala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

VASAVI COLLEGE OF ENGINEERING

(Affiliated to Osmania University)


Hyderabad - 500 031.
DEPARTMENT OF : Computer Science and
engineering
NAME OF LABORATORY : Web Programming and
Networking
Name Roll No.
Page No
ASP.net Database Connection

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;

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


{
protected void Page_Load(object sender, EventArgs e)
{
//Response.Write("HELLO");
}
protected void Button1_Click(object sender, EventArgs e)
{
string sno = T1.Text;
string sname = T2.Text;
string branch = T3.Text;
string constr="Provider = MSDAORA.1;Data Source=rdbms;User
ID=cse14733002;Password=vasavi;Unicode=True";

OleDbConnection con = new OleDbConnection(constr);

con.Open();

string sqll="insert into student values("+sno+",'"+sname+"','"+branch+"')";


OleDbCommand cmd = new OleDbCommand(sqll, con);
cmd.ExecuteNonQuery();
cmd.ExecuteReader(select
con.Close();

}
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{

}
}

VASAVI COLLEGE OF ENGINEERING


(Affiliated to Osmania University)
Hyderabad - 500 031.
DEPARTMENT OF : Computer Science and
engineering
NAME OF LABORATORY : Web Programming and
Networking
Name Roll No.
Page No
Asp

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

<!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>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
Sno
<asp:TextBox ID="T1" runat="server"></asp:TextBox>
&nbsp;<br />
Sname<asp:TextBox ID="T2" runat="server"></asp:TextBox>
<br />
Branch<asp:TextBox ID="T3" runat="server"></asp:TextBox>
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="B1" runat="server" EnableTheming="False"
onclick="Button1_Click" Text="Submit" Width="91px" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
onselecting="SqlDataSource1_Selecting"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM &quot;STUDENT&quot;"></asp:SqlDataSource>
</form>
</body>
</html>

VASAVI COLLEGE OF ENGINEERING


(Affiliated to Osmania University)
Hyderabad - 500 031.
DEPARTMENT OF : Computer Science and
engineering
NAME OF LABORATORY : Web Programming and
Networking
Name Roll No.
Page No
Service wcf
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService" in both
code and config file together.
[ServiceContract]
public interface IService
{
[OperationContract]
int adder(int val1, int val2);

[OperationContract]
string GetData(int value);

[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);

// TODO: Add your service operations here


}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";

[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}

[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
VASAVI COLLEGE OF ENGINEERING
(Affiliated to Osmania University)
Hyderabad - 500 031.
DEPARTMENT OF : Computer Science and
engineering
NAME OF LABORATORY : Web Programming and
Networking
Name Roll No.
Page No
Wcf service

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service" in code, svc
and config file together.
public class Service : IService
{

public int adder(int val1,int val2)


{
return (val1 + val2);
}

public string GetData(int value)


{
return string.Format("You entered: {0}", value);
}

public CompositeType GetDataUsingDataContract(CompositeType composite)


{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}

VASAVI COLLEGE OF ENGINEERING


(Affiliated to Osmania University)
Hyderabad - 500 031.
DEPARTMENT OF : Computer Science and
engineering
NAME OF LABORATORY : Web Programming and
Networking
Name Roll No.
Page No
Adding two numbers using service
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>
</head>
<body>
<form id="form1" runat="server">
<div>

value 1<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


&nbsp;<br />
value 2<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ServiceReference1;

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


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

}
protected void Button1_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(TextBox1.Text);
int b = Convert.ToInt32(TextBox2.Text);

ServiceClient client = new ServiceClient();


int sum = client.adder(a, b);
Response.Write("the sum is:" + sum);

VASAVI COLLEGE OF ENGINEERING


(Affiliated to Osmania University)
Hyderabad - 500 031.
DEPARTMENT OF : Computer Science and
engineering
NAME OF LABORATORY : Web Programming and
Networking
Name Roll No.
Page No
Ajax
Index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function sendRequest(){
var n1= document.
req=new XHttpRequest();
req.open("GET","square.jsp?n1="+n1,false);
req.send();
p.innerHTML=req.responseText;
}
</script>
</head>
<body>
<form >
Number:<input type="number" id="n"/>.
<p id=p></p>
<input type="button" name="b" value="submit" onclick="sendRequest"/>
</form>

</body>
</html>

Square.jsp

<%@ page language="java" contentType="text/html;charset=UTF-8"


pageEncoding="UTF-8"%>
<%
int number = Integer.parseInt(request.getParameter("n1"));
out.println("Square root of "+ number + " is "
+ number*number);
%>
VASAVI COLLEGE OF ENGINEERING
(Affiliated to Osmania University)
Hyderabad - 500 031.
DEPARTMENT OF : Computer Science and
engineering
NAME OF LABORATORY : Web Programming and
Networking
Name Roll No.
Page No
VASAVI COLLEGE OF ENGINEERING
(Affiliated to Osmania University)
Hyderabad - 500 031.
DEPARTMENT OF : Computer Science and
engineering
NAME OF LABORATORY : Web Programming and
Networking
Name Roll No.
Page No

You might also like