This is a SQL Server Data Access example with many overloaded Select statements and several different ways to execute stored procedures.
Here is some code snippet:
public AuthorData(string connection)
{
this.connection = connection;
}
........
public SQLDataReader Select(string commandName)
{
SQLDataReader dr = null;
try
{
SQLConnection cnn = new SQLConnection(this.connection);
cnn.Open();
SQLCommand cmd = new SQLCommand(commandName,cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Execute(out dr);
cmd.ActiveConnection = null;
}
catch(Exception e)
{
ErrorLog errLog = new ErrorLog();
errLog.LogError(e.Message, commandName);
}
return(dr);
}
.............
public void Select(out SQLDataReader dr, string commandName)
{
dr = null;
try
{
SQLConnection cnn = new SQLConnection(this.connection);
cnn.Open();
SQLCommand cmd = new SQLCommand(commandName,cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Execute(out dr);
cmd.ActiveConnection = null;
}
catch(Exception e)
{
ErrorLog errLog = new ErrorLog();
errLog.LogError(e.Message, commandName);
}
}
.............