Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Data;
Using System.Data.SqlClient;
Namespace DAL
{
public class DBHelper
{
Create a link string
public static string sqlconn = "Data source=.;i Nitial catalog=studentdb;integrated security=true ";
Create a linked object
public static SqlConnection conn = new SqlConnection (sqlconn);
How to change and delete
public static bool Exequtenonquery (String sql)
{
Open a linked object
Conn. Open ();
To create a Command object
SqlCommand cmd = new SqlCommand (sql,conn);
Execute Command object
int result = cmd. ExecuteNonQuery ();
Conn. Close ();
if (Result > 0)
{
return true;
}
else {
return false;
}
}
Query method
Public DataTable exequtetable (String sql)
{
Creating a data adapter
SqlDataAdapter da = new SqlDataAdapter (SQL, conn);
DataTable table=new DataTable ();
Da. Fill (table);
return table;
}
}
}
My class of DBHelper