HSS Core DataAccess

The HSS Data Library make its easy to execute stored procedures or free form SQL. Below is an example of using the DataAccess class.

Please see the developer reference for more details hsscore-help.chm

DataAccess.ExecNonQuery()
private int TestExecNonQuery()
{
	int spReturnValue = 0;
	using (DataAccess da = new DataAccess(YourDBConnectionString))
	{
		da.AddWithValue("Parameter Name", "Parameter Value");
		da.AddParam("PName", "PValue", SqlDbType.VarChar, 500, ParameterDirection.Input);
		da.ExecNonQuery("YourSPName", ref spReturnValue);
	}
	Console.WriteLine("spReturnValue: {0}", spReturnValue);
	return spReturnValue;
}


DataAccess.ExecScalar()
public object TestExecScalar()
{
	using (DataAccess da = new DataAccess(YourDBConnectionString))
	{
		da.AddWithValue("Parameter Name", "Parameter Value");
		da.AddParam("PName", "PValue", SqlDbType.VarChar, 500, ParameterDirection.Input);
		return da.ExecScalar("YourSPName");
	}
}

DataAccess.ExecSqlDataReader()
public void TestExecSqlDataReader()
{
	int spReturnValue = 0;
	using (DataAccess da = new DataAccess(YourDBConnectionString))
	{
		da.AddWithValue("Parameter Name", "Parameter Value");
		da.AddParam("PName", "PValue", SqlDbType.VarChar, 500, ParameterDirection.Input);
		using (SqlDataReader sdr = da.ExecSqlDataReader("YourSPName"))
		{
			while (sdr.Read())
			{
				string str = sdr.GetString(sdr.GetOrdinal("FieldName"));
				Console.WriteLine(str);
			}
		}
	}
}

DataAccess.ExecDataRowReader()
public void TestExecDataRowReader()
{
	int spReturnValue = 0;
	using (DataAccess da = new DataAccess(YourDBConnectionString))
	{
		da.AddWithValue("Parameter Name", "Parameter Value");
		da.AddParam("PName", "PValue", SqlDbType.VarChar, 500, ParameterDirection.Input);
		using (DataRowReader drr = da.ExecDataRowReader("YourSPName"))
		{
			while (drr.Read())
			{
				string str = drr.GetString(drr.GetOrdinal("FieldName"));
				Console.WriteLine(str);
			}
		}
	}
}

Last edited Aug 8, 2010 at 2:44 PM by hyspdrt, version 2

Comments

No comments yet.