My class of DBHelper

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.