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
Cj Mah
NA
0
2k
my EditStaff problem
Dec 29 2015 5:45 AM
the problem is that i put the query string as StaffId not Id. it give me this error,
Invalid attempt to read when no data is present. So help me fixed the problem.
string staffId = null;
SqlConnection conn = null;
SqlCommand cmd = null;
string connectionString = null;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlDataReader dr = null;
connectionString = ConfigurationManager.ConnectionStrings["FacilityCS"].ConnectionString;
conn = new SqlConnection(connectionString);
string sql = "SELECT * from Staff";
try
{
cmd = new SqlCommand(sql, conn);
conn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
ListItem item = new ListItem(dr["Title"].ToString(), dr["StaffId"].ToString());
ddlTitle.Items.Add(item);
}
dr.Close();
}
catch (Exception ex)
{
lblOutput.Text = "Error Message: " + ex.Message;
}
finally
{
if (conn != null)
conn.Close();
}
if (Request.Params["StaffId"] != null)
{
staffId = Convert.ToString(Request.Params["StaffId"]);
sql = "SELECT * from Staff";
try
{
cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@StaffId", staffId);
conn.Open();
dr = cmd.ExecuteReader();
tbStaffId.Text = dr["StaffId"].ToString();
tbPassword.Text = dr["Password"].ToString();
tbStaffName.Text = dr["StaffName"].ToString();
tbEmail.Text = dr["Email"].ToString();
tbPhoneNo.Text = dr["PhoneNo"].ToString();
ddlTitle.SelectedValue = dr["Title"].ToString();
rbRole.SelectedValue = dr["Role"].ToString();
dr.Close();
}
catch (Exception ex)
{
lblOutput.Text = "Error Message: " + ex.Message;
}
finally
{
if (conn != null)
conn.Close();
}
}
}
else
{
lblOutput.Text = "Error. There is no ID to retrieve from the DB.";
}
}
Reply
Answers (
3
)
hosting website - File upload and read IIS root in asp.net
hidden field validation