Crash893
Jul 11th, 2007, 12:19 PM
Hi all
I want to make a sub that i send a Query and maybe some other variables (server location and table name) and i want it to return a datatable in a dataset that i can then feed into other subs for data manipulation as well as fill a DGV
the question is , if i have the sub return as a dataset how can i do more than one thing with it with out having to re run the sub again and again.
is it efficient to do something like "Dataset DS = subprocdure(query)" and then use DS in my code and if i do this wont it cause a duplication of data? (basicly ill have two containers sitting in memory)
Here is my code ( and please PLEASE feel free to correct anything else you think should be improved)
Ps yes i know the sub is names stupid thats just while im playing with it
private void button2_Click(object sender, EventArgs e)
{
string query = "SELECT gci_requests.id, gci_requests.ref_num, gci_requests.summary, gci_requests.description, gci_requests.open_date, gci_requests.last_modified_date, gci_requests.close_date, gci_requests.resolve_date, gci_requests.status, gci_requests.rootcause, gci_requests.priority, gci_requests.urgency, gci_requests.problem, gci_requests.type, gci_requests.category_name, gci_requests.assignee_adaccount, gci_requests.reportedby_adaccount, gci_requests.customer_adaccount, gci_requests.group_name FROM mdb_rpt.dbo.gci_requests gci_requests WHERE gci_requests.group_name='USAT-Publishing Solutions'";
dataGridView1.DataMember = "gci_requests";
dataGridView1.DataSource = Test(query); //<--- this is what i want to do better becuase i might need to use it somewhere else
}
private DataSet Test(string query)
//worktodo
// add more prams for server and tablename
// improve catch to post error
{
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection("Server=gci-mocsqdb01;Database=mdb_rpt;Uid=caiahd_rpt;Pwd=dashboard;");//Driver={SQL Server};
try
{
conn.Open();
String SelectCmdString = query;
SqlDataAdapter da = new SqlDataAdapter(SelectCmdString, conn);
da.Fill(ds, "gci_requests");
}
catch
{ MessageBox.Show("database connection Failed"); }
finally
{
conn.Close();
}
return ds;
}
I want to make a sub that i send a Query and maybe some other variables (server location and table name) and i want it to return a datatable in a dataset that i can then feed into other subs for data manipulation as well as fill a DGV
the question is , if i have the sub return as a dataset how can i do more than one thing with it with out having to re run the sub again and again.
is it efficient to do something like "Dataset DS = subprocdure(query)" and then use DS in my code and if i do this wont it cause a duplication of data? (basicly ill have two containers sitting in memory)
Here is my code ( and please PLEASE feel free to correct anything else you think should be improved)
Ps yes i know the sub is names stupid thats just while im playing with it
private void button2_Click(object sender, EventArgs e)
{
string query = "SELECT gci_requests.id, gci_requests.ref_num, gci_requests.summary, gci_requests.description, gci_requests.open_date, gci_requests.last_modified_date, gci_requests.close_date, gci_requests.resolve_date, gci_requests.status, gci_requests.rootcause, gci_requests.priority, gci_requests.urgency, gci_requests.problem, gci_requests.type, gci_requests.category_name, gci_requests.assignee_adaccount, gci_requests.reportedby_adaccount, gci_requests.customer_adaccount, gci_requests.group_name FROM mdb_rpt.dbo.gci_requests gci_requests WHERE gci_requests.group_name='USAT-Publishing Solutions'";
dataGridView1.DataMember = "gci_requests";
dataGridView1.DataSource = Test(query); //<--- this is what i want to do better becuase i might need to use it somewhere else
}
private DataSet Test(string query)
//worktodo
// add more prams for server and tablename
// improve catch to post error
{
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection("Server=gci-mocsqdb01;Database=mdb_rpt;Uid=caiahd_rpt;Pwd=dashboard;");//Driver={SQL Server};
try
{
conn.Open();
String SelectCmdString = query;
SqlDataAdapter da = new SqlDataAdapter(SelectCmdString, conn);
da.Fill(ds, "gci_requests");
}
catch
{ MessageBox.Show("database connection Failed"); }
finally
{
conn.Close();
}
return ds;
}