Ok Title may not be clear so let me explain.
I have 2 classes, “Form1” and “webinfo”.
in “webinfo” I run the following code:
class WebInfo
{
string myConnVRM = "Data Source = datascource;" +
"Initial Catalog = catalog;" +
"Persist Security Info=True;" +
"User ID=ID;" +
"Password=PASS;" +
"providerName=System.Data.SqlClient;";
public WebInfo()
{
}
public void GetVRMs(string vRMs, string start, string end, string acc)
{
DataTable vrmTable = new DataTable();
SqlConnection connVRM = new SqlConnection(myConnVRM);
connVRM.Open();
SqlCommand cmdVRM = new SqlCommand("SELECT Ac, Vrm, Make, Model, MamengineSize, date FROM ReturnValue WHERE convert(varchar,[Date],101) between @StartDate and @EndDate and [AC]=@Acct", connVRM);
cmdVRM.Parameters.AddWithValue("@acct", acc);
cmdVRM.Parameters.AddWithValue("@from", start);
cmdVRM.Parameters.AddWithValue("@too", end);
SqlDataAdapter vrmAdapter = new SqlDataAdapter(cmdVRM);
vrmAdapter.Fill(vrmTable);
//bind to data grid and display??
}
}
as you can see I connect to a server, run a query and finally fill my table with the results.
my form class then calls GetVRms method, passes the relevent info.
But what I need to do is now bind this table to the datagrid on my form so i can display. Only problem is how do i use the table from this class?
Am i totally over thinking this? is it as simple as webinfo.vrmtable?
Many Thanks In Advance
Change
to
then put
at the end of the method.
Then bind to the table in your UI like this: