SQL ODBC Helper

HOW TO:

Default.aspx.cs (SQL Data Reader)
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

//- Sql Connection String
var MyStringConnection = "data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true";

//- Instantiate the ODBC Class
ncTools.ODBCHelper oDB = new ncTools.ODBCHelper();
//- Get the Records
SqlDataReader dr = oDB.SqlRecordSet("SELECT * FROM Customers", MyStringConnection);
//- Check for end of file
if (dr.HasRows)
{
   //- Loop through all record found
   while (dr.Read())
   {
      //- Do your thing here
    }
}
dr.Close(); 
oDB = null; 

//=====================================================================================
//-- SQL Execute a store procedure.
//=====================================================================================
//- Sql Connection String
var MyStringConnection = "data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true";
//- Instantiate the ODBC Class
ncTools.ODBCHelper oDB = new ncTools.ODBCHelper();
//- Get the result
int iResult = oDB.SqlExecuteQuery("spExecuteStoreProcedure", MyStringConnection);
if (iResult>0)
{
  //- Successfully Executed    
}
oDB=null;


Add Feedback