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);
}
}
}