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

How to send variables from on SWF flex file to another SWF file Using Flex.

How to Communicate From one SWF Flex file to another SWF Flex File ? See the below example, This is loading external swf flex file into parent SWF File and sharing the data or variable from parent to child and child to parent. Parent.mxml CODE: 1: <?xml version="1.0" encoding="utf-8"?> 2: <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%"> 3: <mx:Script> 4: <![CDATA[ 5: import mx.events.CloseEvent; 6: import mx.controls.SWFLoader; 7: import mx.managers.PopUpManager; 8: import mx.containers.TitleWindow; 9: import mx.controls.Alert; 10: 11: public var tw:SWFPlaceHolder; 12: 13: public function launchExternalSWF(title:String,swfFilePath:String):void{ 14: 15: /

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

How To Change Form Action at Runtime

How to change Form action at runtime using javascript. This the example which will change html form action at runtime. CODE: 1 :   <html> 2 :   <head> 3 :   <Script Language="javascript"> 4 :   function change_action(){ 5 :   var frm_obj=document.getElementById("frm"); 6 :   frm_obj.action="http://www.google.com"; 7 :   } 8 :   </Script> 9 :   </head> 10 :   <body> 11 :   <form id="frm" action="abc.php" method="post" onsubmit="return change_action()"> 12 :   UID &nbsp;&nbsp;<input type="text"><br> 13 :   PWD <input type="Password"><br><br> 14 :   <input type="submit" value="submit"> 15 :   </form> 16 :   </body> 17 :   </html>