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
Murugavel S
NA
83
24k
Asp.net Web Application
Jul 17 2015 1:38 AM
Hi Friendss
i created one web form contains textboxes ,one gridview and button..
when click the button the values in the textboxes should add into the db and display in gridview.. for that i created two functions..
one is to insert values in db and other is to display db values into gridview..
My Question is to how display the db values into gridview by button click event.. err- invalid attempt to call Read when reader is closed.
=============
Below function is to add values to DB:
private void loadTable()
{
SqlConnection con = null;
try
{
SqlConnectionStringBuilder connectionString = getConString();
con = new SqlConnection();
con = new SqlConnection(connectionString.ToString());
con.Open();
string sqlQry = "insert Query";
SqlCommand cmd = new SqlCommand(sqlQry, con);
SqlDataReader reader;
reader = cmd.ExecuteReader();
gridview.DataSource = reader;
gridview.DataBind();
}
catch (Exception ex)
{
}
finally
{
con.Close();
}
}
======================
Below Function is to display the db Values into Gridview:
private void loadGrid()
{
SqlConnection con = null;
try
{
SqlConnectionStringBuilder connectionString = getConString();
con = new SqlConnection();
con = new SqlConnection(connectionString.ToString());
con.Open();
string sqlQry = "select * from table";
SqlCommand cmd = new SqlCommand(sqlQry, con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
gridview.DataSource = ds;
gridview.DataBind();
}
catch (Exception ex) here throwing error "invalid attempt to call read when reader is closed"
{
}
finally
{
con.Close();
}
}
button click event
{
loadTable();
loadGrid();
}
the error in loadgrid functions in only in button click event, the same loadgrid function is also in page load form..
Thanks in advance
Reply
Answers (
3
)
custom error pages not working in asp.net webforms
Multiple dropdown select in mvc using jquery and css