How to create an empty tableAdapter or deliver a tableAdapter to extern function
-
Hello community! I'm new here. My Question is: Is it possible to create a TableAdapter programmatically or deliver it to an extern function? The reason: I want to create an Class Library which should take care of DataBase activities in my application. One reason is a function i wrote that compares the loaded Row with the Row in DataBase before sending an Update-Command, which i want to use in all applications. My consideration: The Library contains an class "DBCaretaker". On creating this class, it receives the DataSet and the TableAdapters. After that, filling DataSets, Updating Tables and further actions will be executed by functions in this Library. Is this possible? Or do you have an alternative proposal? Greetings, Robert
-
Hello community! I'm new here. My Question is: Is it possible to create a TableAdapter programmatically or deliver it to an extern function? The reason: I want to create an Class Library which should take care of DataBase activities in my application. One reason is a function i wrote that compares the loaded Row with the Row in DataBase before sending an Update-Command, which i want to use in all applications. My consideration: The Library contains an class "DBCaretaker". On creating this class, it receives the DataSet and the TableAdapters. After that, filling DataSets, Updating Tables and further actions will be executed by functions in this Library. Is this possible? Or do you have an alternative proposal? Greetings, Robert
If you say:
public DataSet GetUsers()
{
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Users", connectionstring);
DataSet dataset = new DataSet();
adapter.Fill(dataset, "Users");
return dataset;
}Here you would rather want to pass the dataset to extern function and make sure the receiving function is requesting for a dataset to be returned e.g
DateSet datasetfromfrontend = NameOfClass.GetUsers();//calling the method above
This will return a dataset and you can check for tables e.g
DataTable table = datasetfromfrontend.Tables[0];
Good luck
-
If you say:
public DataSet GetUsers()
{
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Users", connectionstring);
DataSet dataset = new DataSet();
adapter.Fill(dataset, "Users");
return dataset;
}Here you would rather want to pass the dataset to extern function and make sure the receiving function is requesting for a dataset to be returned e.g
DateSet datasetfromfrontend = NameOfClass.GetUsers();//calling the method above
This will return a dataset and you can check for tables e.g
DataTable table = datasetfromfrontend.Tables[0];
Good luck
This way i could go, but i wanted something little different: I don't want to create an adapter with just one SELECT command, rather i would like to go on something like this:
public void myFunction(DataSet myDataSet, "TableAdapter" myTableAdapter) { // working with both }
Or this:public void myFunction(DataSet myDataSet) { "TableAdapter" myTableAdapter = myDataSetTableAdapterCollection.TableAdapter[0]; }
Then i could use all the SQL commands of this TableAdapter, and don't have to write them manually.