My Professional Profile

I am Johnson Augustine Sr.Software Engineer and System Architect. I have 10 Yrs of hands on expertise in ASP.net MVC 5 , Angular 5 , C# MVC Razor, WPF MVVM , Android , IOS Swift 3 , IOS11 MSSQL,MySQL Database,,PHP,C/C++/Visual C++/G++/QT++,Com,DirectX,Open CV,EMGU CV , embedded System Development , [Raspberry PI]. ,html,Javascript,Jquery,Ajax.CSS , Networking ,Cyber security, Ethical Hacking You can see my professional profile at http://linkedin.com/in/johnsontaugustine Email : johnsonaugustine@live.com

Wednesday, 19 December 2012

ASP.net C# Data base connection with MS SQL


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// Summary description for cls_LIFE_CONNECT
/// </summary>
public class cls_Connectionclass_CONNECT
{
   private  SqlCommand cmd = new SqlCommand();
   private  SqlConnection con = new SqlConnection();
   public  SqlDataAdapter da = new SqlDataAdapter();
   public DataTable dt;

   public cls_Connectionclass_CONNECT()
{
        con.ConnectionString = "server=MYSERVER;database=DB_NyDb;uid=sa;pwd=admin123";

}
    private SqlConnection connect() // Openning connection
    {
        if (con.State == ConnectionState.Open)
        {
            con.Close();
        }
        con.Open();
        return con;
    }
    public DataTable table(string query)  // return Data tables or rows of data
    {

        cmd.Connection = connect();
        cmd.CommandText = query;
        da.SelectCommand = cmd ;
        dt = new DataTable();
        da.Fill(dt);
        return dt;
    }

    public int exe_non_query(string query) // execute query , return an integer as result
    {
        cmd.Connection = connect();
        cmd.CommandText = query;
        return cmd.ExecuteNonQuery();
    }
    public object exe_scalar(string query) // Retrieve single values
    {
        cmd.Connection = connect();
        cmd.CommandText = query;
        return cmd.ExecuteScalar();
    }

}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.