I am new to c#. I have a class called "DBConnection" and a function called "getTransportDate()"
Basically, I just want to get the Datatable value from a class and display it a form datagrid view. How to can I achieved this ?
What I've done so far:
On button click
- private void btnTransport_Click(object sender, EventArgs e){DBConnection.getTransportData();}
My DBConnection Class function
- public DataTable TDataTable = new DataTable();public SqlDataAdapter TDataAdapter = new SqlDataAdapter();
- public void getTransportData()
- {
- using (SqlCommand cmd = new SqlCommand(@"
- SElECT * FROM IRFormTransport
- ",dbconn))
- {
- cmd.ExecuteNonQuery();
- TDataAdapter.SelectCommand = cmd;
- TDataTable.Clear();
- TDataAdapter.Fill(TDataTable);
- }
- }
My ReportList form
- DBConnection DBConnection = new DBConnection();
- private void ReportList_Load(object sender, EventArgs e)
- {
- ReportGrid.DataSource = DBConnection.TDataTable;
- }
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Uttam ChaturvediRank #477 · 5.2K reputationPosted Oct 18, 2018, 12:11 AM EDT