Skip to main content

C Sharp User Define SQL Database Class

This is the simple user define SQL Database Class. It is useful to avoid redundancy of the code.


Database Class In C#
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public class _Database
{
public SqlConnection con;
public SqlCommand com = null;
public SqlDataReader dr = null;
public SqlDataAdapter da = null;
public DataSet ds = null;
public String glQuery = "";
public String glnonQuery = "";
public const int EXECUTE_NONE_QUERY = 1;
public const int EXECUTE_QUERY = 2;
public const int DATA_ADAPTER = 3;

// connection for data list paging
public SqlConnection globalcon = new SqlConnection("server=**;uid=**;pwd=***;Database=**");
public _Database() { }
public void Query(String SqlQuery)
{
this.glQuery = this.Get_DataBasePrefix(SqlQuery);
}
private String Get_DataBasePrefix(String str)
{
return str.Replace("#__", "GD_").ToString();
}
public void ConnectDB()
{
try
{
con = new SqlConnection();
con.ConnectionString = "server=*****;uid=**;pwd=****;Database=***";
con.Open();
}
catch (Exception ex)
{
}
}
public void CloseDB()
{
this.con.Close();
this.con.Dispose();
}
public bool Read()
{
return this.dr.Read();
}
public void ExecuteQuery(int Mode)
{
try
{
if (Mode == EXECUTE_NONE_QUERY) // Excutenonequery
{
this.com = new SqlCommand(this.glQuery, this.con);
this.com.ExecuteNonQuery();
}
else if (Mode == EXECUTE_QUERY) // Execute Query
{
this.com = new SqlCommand(this.glQuery, this.con);
this.dr = this.com.ExecuteReader();
}
else if (Mode == DATA_ADAPTER) // Data Adapter
{
this.da = new SqlDataAdapter(this.glQuery, this.con);
this.ds = new DataSet();
this.da.Fill(this.ds);
}
}
catch (Exception ex)
{
}
}
public bool HasRows()
{
if (this.dr.HasRows)
{
return true;
}
else
{
return false;
}

}
}

Comments

Popular posts from this blog

Flex Interview Questions

1) What is Flex? Flex is used to devleop Rich Internet Application (RIA) You can both desktop & web based applicaiton.It is markup language and object-oriented languages its many syntax match with flash action script. Flex Developers use typically five distinct phases to develoep Rich Internet Application. Design Configure Build Deploy Secure 2) How do i get Page URL and Query String ? We can use mx.core.Application.application.url (mx.core)package to work with current page URL. & query string. 3) Describe flex component file types ? There are following file types we can use in flex. extension .mxml - a component implemented as an MXML file. extension .as - a component implemented as an ActionScript class. extension .swc - a SWC file contains components in a packge. 4) Difference between target & currentTarget ? target : This property is set by the dispatchEvent() method. You cannot change this to a different object. currentTarget : This property is set by component instan...

Ethereum Programming Language

Solidity: The Programming Language of Ethereum Blockchain technology has revolutionized various industries by introducing decentralized and secure applications. Ethereum, one of the leading blockchain platforms, has gained immense popularity due to its ability to support smart contracts, which enable the execution of self-executing code with predefined rules. To write these smart contracts, developers use Solidity, a high-level, contract-oriented programming language specifically designed for Ethereum. In this article, we will explore Solidity in detail, including its features, syntax, use cases, advantages, and challenges. 1. Introduction to Solidity Solidity was introduced by Gavin Wood in 2014 and is the primary language for developing smart contracts on the Ethereum platform. It is a statically-typed language that supports inheritance, libraries, and complex user-defined types. Solidity code is compiled into bytecode, which can be executed on the Ethereum Virtual Machine (EVM), mak...

How to Format My Source Code For Blogger ?

How to format my source code for blogger, blog, Blogging, weblog & website ? Now you can format you source code for blogger, blog, Blogging, weblog & website using online source code formatter. This application build in javascript. This source code beautifier or formatter provide for your blogger, Blog and websites a good code indentation. You can can format your source code with alternative background using <pre> tag. It does not add unnecessary tags in formatted source code excpet <pre> and <code> so just try onto your source code for blog or blogging & website posts . This is absolutly free online line source code formatter tool for your blogger & website. http://codeformatter.blogspot.com/ See example.. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT=""> <META NAME="A...