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
Chevy Mark Sunderland
NA
188
167.3k
Object reference not set to an instance of an object
Apr 17 2013 2:07 PM
Hello guys and good day, I need your help.
This is my net code, I've this error in object dr, why?
Can you help me? Thank you in advance.
[code]
protected void BindEmployeeDetails()
{
myConnectionString.Open();
httpCookie CustInfo = Request.Cookies["id"];
SQL = "SELECT * FROM ";
SQL = SQL + " tbl ";
SQL = SQL + " WHERE 1 ";
if (CustInfo != null)
{
SQL = SQL + " AND id = " + Request.Cookies["id"].ToString() + " ;";
}
OdbcCommand cmd = new OdbcCommand(SQL, myConnectionString);
OdbcDataAdapter da = new OdbcDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
OdbcDataReader dr = null;
if (dr.Read())
{
if (ds.Tables[0].Rows.Count > 0)
{
gvDetails.DataSource = ds;
gvDetails.DataBind();
}
else
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gvDetails.DataSource = ds;
gvDetails.DataBind();
int columncount = gvDetails.Rows[0].Cells.Count;
gvDetails.Rows[0].Cells.Clear();
gvDetails.Rows[0].Cells.Add(new TableCell());
gvDetails.Rows[0].Cells[0].ColumnSpan = columncount;
gvDetails.Rows[0].Cells[0].Text = "No record found";
}
}
else
{
Response.Write("No user");
}
myConnectionString.Close();
}
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 43: OdbcDataReader dr = null;
Line 44:
Line 45: if (dr.Read())
Line 46: {
Line 47: if (ds.Tables[0].Rows.Count > 0)
[/code]
Reply
Answers (
3
)
abt asp.net data transfer
how to use sqlserver views in asp.net C#?