Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
4
Answers
Plz Solve my prob. I m using a mathod in a class which return dataset obj. but it not working.
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Vikas Ahlawat
15y
1.9k
1
Reply
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
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
how to get data from SQL to hide empty cell
dataGridview event name , which is fire when we click on any where in the row?