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
Vikas Ahlawat
NA
564
818.1k
Plz Solve my prob. I m using a mathod in a class which return dataset obj. but it not working.
Sep 23 2009 7:47 AM
i have make a class
class Class2
{
public DataSet retdataset()
{
SqlConnection con = new SqlConnection("Data Source =.\\SQLEXPRESS;Initial Catalog = schoolmgt; password=; Integrated Security = true;");
con.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("retrive_all_students_reg
_detail", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.Fill(ds);
con.Close();
return (ds);
//dataGridView2.DataSource = ds.Tables[0];
}
}
now i call this on button click event
private void button1_Click(object sender, EventArgs e)
{
Class2 o = new Class2();
dataGridView1.DataSource = o.retdataset();
}
when i run my window application and click the button then no data appear in datagridview
IF I WRITE THE WHOLE CODE UNDER BUTTON CLICK EVENT THEN THIS IS WORKING
LIKE BELLOW CODE
private void button1_Click(object sender, EventArgs e)
{
//Class2 o = new Class2();
//dataGridView1.DataSource = o.retdataset();
SqlConnection con = new SqlConnection("Data Source =.\\SQLEXPRESS;Initial Catalog = schoolmgt; password=; Integrated Security = true;");
con.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("retrive_all_students_reg
_detail", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
con.Close();
}
CAN ANY ONE TELL MY MISTAKE??
PLZ HELP ME
Reply
Answers (
4
)
licence agreement setup project in C#
dataGridview event name , which is fire when we click on any where in the row?