as this is a staic method:
Just add this line wherever you'd like to use it.
General_function.Get_Single_Value("Your SQL Query goes here");
However this method might not be threadsafe as multiple threads could access the database_Object at once (which has to bee a static object too). You'll need to make sure that your database_Objects are threadsafe.
In addition you should make sure to release the resources after the call otherwise you might end up with lots of open connection (running into problems if you're using a connection pooling mechanism)
If the
DbConnection
and
DbCommand
implement the IDisposable Interface use them like this:
using(var cn = database_Object.GetConnection(database_Object.Provider)) {
if(cn.State == ConnectionState.Closed) {
cn.ConnectionString = My.Settings.Trasns_DataConnectionString;
cn.Open();
}
using(var cmd = database_Object.GetCommand(database_Object.Provider)){
cmd.Connection = cn;
cmd.CommandText = SQLQuery;
return cmd.ExecuteScalar;
}
}
You won't even have to use exception handling to close the connections as the using statement takes care of disposing those objects.