//File1
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Query String Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Query String Example</h3>
<label>Name :</label><br />
<asp:TextBox runat="server" ID="txtname"></asp:TextBox><br />
<label>Email :</label><br />
<asp:TextBox runat="server" ID="txtmail"></asp:TextBox><br /><br />
<asp:Button runat="server" ID="btnsubmit" OnClick="btnsubmit_Click" Text="Go to other webform" />
</div>
</form>
</body>
</html>
//File2
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Query String Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Query String Example</h3>
<label>Name :</label> <asp:Label> runat="server" ID="lblname"></asp:Label><br />
<label>Email :</label> <asp:Label> runat="server" ID="lblemail"></asp:Label>
</div>
</form>
</body>
</html>
//File 1 Code Behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Training
{
public partial class QueryString1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnsubmit_Click(object sender, EventArgs e)
{
Response.Redirect("QueryString2.aspx?Name="+txtname.Text+"&Email="+txtmail.Text+"");
}
}
}
//File2 Code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Training
{
public partial class QueryString2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblname.Text = Request.QueryString["Name"];
lblemail.Text = Request.QueryString["Email"];
}
}
}
ADO.NET is a set of classes (a framework) to interact with data sources such as databases. ADO is the acronym for ActiveX Data Objects. It allows us to connect to underlying data or databases. It has classes and methods to retrieve and manipulate data.
ADO.NET also allows us to connect with database by using ConnectionString
In this diagram, we can see that there are various types of applications (Web Application, Console Application, Windows Application and so on) that use ADO.NET to connect to databases (SQL Server, Oracle, OleDb, ODBC, XML files and so on).
<connectionStrings>
<add name="connstr" connectionString="Data Source=ADMIN;Initial Catalog=REVOLUTION;Integrated Security=True"/>
</connectionStrings>
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString);
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Revolution
{
public partial class Contact : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnsubmit_Click(object sender, EventArgs e)
{
con.Close();
SqlCommand cmd = new SqlCommand("insert into RevEnquiryData values('" + txtname.Text + "','" + txtcontact.Text + "','" + txtmail.Text + "','" + txtdes.Text + "',@date)", con);
cmd.Parameters.AddWithValue("@date", DateTime.Now.ToShortDateString());
con.Open();
cmd.ExecuteNonQuery();
txtcontact.Text = "";
txtdes.Text = "";
txtmail.Text = "";
txtname.Text="";
this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "swal('Enquiry Sent Successfully,Thank You..! We will contact you very soon..!','','success');", true);
}
}
}