An extensible Database class using Generics in C#

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Sql;
using System.Data.SqlClient;

namespace MMO
{
public class db
{
SqlConnection dbC;
public SqlCommand cmd;
public SqlDataReader dr;

public db()
{
dbC = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
dbC.Open();
}

public int SetCommand(string CommandName, CommandType type)
{
try
{
cmd = new SqlCommand(CommandName, dbC);
cmd.CommandType = type;
return 1;
}
catch
{
return 0;
}
}

public int AddParam(string name, SqlDbType type, int ParamSize, T value)
{
try
{
cmd.Parameters.Add(name, type, ParamSize).Value = value;
return 1;
}
catch
{
return 0;
}
}

public bool Read()
{
try
{
dr = cmd.ExecuteReader();
return true;
}
catch
{
return false;
}
}

public object RunScalar()
{
return cmd.ExecuteScalar();
}

public bool RunNoQuery()
{
try
{
cmd.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
}
}
}

Accessing Excel with OLEDB C#

String Path;
Path = “.\xls\”;
DirectoryInfo dir = new DirectoryInfo(Path);

String ExcelConnectionString;
OleDbDataReader dr;

ExcelConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” +
Path + f.Name + “;Extended Properties=”Excel 8.0;HDR=Yes;IMEX=1″;”;

con = new OleDbConnection(ExcelConnectionString);
con.Open();

using (OleDbCommand myCommand = new OleDbCommand(“select ” +
“string1,” +
“string2″, con))
{
using (dr = myCommand.ExecuteReader())
{
while (dr.Read())
{

Console.WriteLine(“string1: ” + dr.GetString(0));
Console.WriteLine(“string2: ” + dr.GetString(1));
} // end while

} // end DR using

} // end OLEDB using

SQL Cursors

[code lang="sql"]

declare @datefrom datetime
declare @clientid int

DECLARE arrears_client_cursor CURSOR FOR
SELECT top 10 cc.id
FROM client_creditcontrol ccc
INNER JOIN client_contact cc ON cc.id = ccc.clientid

OPEN arrears_client_cursor
FETCH NEXT FROM arrears_client_cursor INTO @clientid

WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @clientid

FETCH NEXT FROM arrears_client_cursor INTO @clientid
END

CLOSE arrears_client_cursor
DEALLOCATE arrears_client_cursor

[/code]
Posted in SQL

validating checkbox values using jquery

$(document).ready(function(){
var siteSelected=new Boolean(false);

/* check the element :before might be a stupid asp.net span */
$(‘.buttonvalidator input’).click(function(){

jQuery(‘.sitesValidator input:checkbox’).each( function(){
if (this.checked == true){
siteSelected=true
}
});

alert(siteSelected);

return siteSelected;
});
});