Can anyone tell me if this class will function properly...I'm using MS Visual Studio 2005, using C#. I notice there's no C# forum but hopefully u guys are familiar with the language...than ks in advance
Code:
class esodbconnection
{
public DataViewManager fnGetConnectedToDatabase(string dbname, string tablename, string tablename1, string whereclass, string groupbyclass)
{
ResortApplication.conf configdb = new conf();
//this is creating the connection string
string xmldb = configdb.fnGetKeyConfig(dbname);
//here I declare my command string
string sSQL = "select * from " + tablename + tablename + whereclass + groupbyclass;
//Creates an SQL Data Adapter
SqlDataAdapter dataAdapter = new SqlDataAdapter();
//select the stuff into the data adapter
dataAdapter.SelectCommand = new SqlCommand();
try
{
dataAdapter.SelectCommand.CommandText = sSQL;
//this is creating the database connection
dataAdapter.SelectCommand.Connection = new SqlConnection(xmldb);
//open connection
dataAdapter.SelectCommand.Connection.Open();
dataAdapter.SelectCommand.ExecuteScalar();
}
catch (Exception ex)
{
MessageBox.Show("Error in connection ..." + ex.Message);
}
//Instantiate a DataSet
DataSet mydataset = new DataSet();
//Gets a collection that provides the master mapping
//between a source table and a DataTable
dataAdapter.TableMappings.Add("Table", tablename);
/*A data adapter object utilizes the Fill method
to populate a DataSet or a DataTable object with data
retrieved by a SELECT command. */
dataAdapter.Fill(mydataset);
//When binding a DataSet, .NET automatically uses the corresponding
//DataViewManager provided through the DataSet.DefaultViewManager property
DataViewManager dviewmanager = mydataset.DefaultViewManager;
dataAdapter.SelectCommand.Connection.Close();
return dviewmanager;
}
}
Comment