TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
15
6.2k
How to access a Datatable value from a class to form
Oct 17 2018 9:06 PM
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;
}
How can I achieved that ? Thanks.
Reply
Answers (
1
)
How to implement Threading
System.InvalidCastException: 'Specified cast is not valid