Click here to Skip to main content
15,867,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
SqlCommand cm = new SqlCommand(Query,con);  
        SqlDataAdapter da = new SqlDataAdapter(cm);
        DataSet ds = new DataSet();
        da.Fill(ds);
        TextBoxID.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["JobseekerID"].ToString();
        TextBoxUsername.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["UserName"].ToString();
        TextBoxFirst.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["First_Name"].ToString();
        TextBoxLast.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Last_Name"].ToString();
        TextBoxGender.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Gender"].ToString();
        TextBoxContact.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Contact_No"].ToString();
        TextBoxAge.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Age"].ToString();
        TextBoxDOB.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["DOB"].ToString();
        TextBoxNric.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["NRIC_No"].ToString();
        TextBoxNationality.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Nationality"].ToString();
        TextBoxAdd.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Address"].ToString();
        TextBoxPostal.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Postal_Code"].ToString();
        TextBoCountry.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Country"].ToString();
        TextBoxEmail.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["EmailID"].ToString();



object instance not set to an instance of an object c#

TextBoxID.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["JobseekerID"].ToString();
Posted
Updated 9-Sep-14 20:51pm
v2
Comments
Thanks7872 10-Sep-14 2:52am    
In the line you pointed out, check for the null object and rectify such that it should not be null at that line.

1 solution

We can't tell - and we can't look, because we don't have access to your query, or to your data.

There are four basic possibilities:
1) Your query does not return a table called Tbl_JobseekerPersonalDetails
2) Your query returns the table, but there are no rows in the table
3) Your query returns the table, and it has rows, but there is no column called JobseekerID
4) Your query returns the table, and it has rows, and there is a column, but TextBoxID is null.

Which of these it is is up to you: use the debugger, look at your code when the problem occurs and find out which of these is the case.
If you can't work the debugger, then you need to learn, but you can help find out by splitting the line:
C#
var dt = ds.Tables["Tbl_JobseekerPersonalDetails"];
var row = dt.Rows[0];
var col = row["JobseekerID"];
TextBoxID.Text = col.ToString();
Which line it fails on will tell you which problem it is: you can then look back in your code to find out why is it null.
 
Share this answer
 
Comments
Member 11071167 10-Sep-14 3:00am    
string Query = "select UserName,First_Name,Last_Name,Gender,Contact_No,DOB,NRIC_No,Nationality,Address,Postal_Code,"
+"Status,EmailID,Age,Country,EducationID,University,Feild_Of_Study,Certification,Education_Level,ProfessionID,Work_Experience,"
+"Latest_Position,Career_Level,Latest_Salary,Expected_Salary,Availability,Functional_Area,Key_Skills from"
+"Tbl_JobseekerPersonalDetails, Tbl_JobseekerUEducationalDetails, Tbl_JobseekerProfessionDetails where"
+"Tbl_JobseekerPersonalDetails.JobseekerID=Tbl_JobseekerUEducationalDetails.JobseekerID and Tbl_JobseekerPersonalDetails.JobseekerID=Tbl_JobseekerProfessionDetails.JobseekerID";

This is the query im using
OriginalGriff 10-Sep-14 3:44am    
And?
Which part of this gives null? Without your database as well, and the data it contains the only person who can tell is you...
Member 11071167 10-Sep-14 21:02pm    
query runs in database..

int ID = Convert.ToInt32(Request.QueryString["JobseekerID"]); //Label1.Text = ID;
SqlConnection con = new SqlConnection(CS);
con.Open();

SqlCommand cm = new SqlCommand(Query,con);
SqlDataAdapter da = new SqlDataAdapter(cm);
DataSet ds = new DataSet();
da.Fill(ds);
TextBoxID.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["JobseekerID"].ToString();
TextBoxUsername.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["UserName"].ToString();
TextBoxFirst.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["First_Name"].ToString();
TextBoxLast.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Last_Name"].ToString();
TextBoxGender.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Gender"].ToString();
TextBoxContact.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Contact_No"].ToString();
TextBoxAge.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Age"].ToString();
TextBoxDOB.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["DOB"].ToString();
TextBoxNric.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["NRIC_No"].ToString();
TextBoxNationality.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Nationality"].ToString();
TextBoxAdd.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Address"].ToString();
TextBoxPostal.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Postal_Code"].ToString();
TextBoCountry.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["Country"].ToString();
TextBoxEmail.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["EmailID"].ToString();

Shows error in da.Fill(ds);
OriginalGriff 11-Sep-14 3:14am    
So look at it with the debugger and follow back until you find the null value.
I can't do that for you: I can't run your code.
So start with a breakpoint on the line, and user the debugger to work backwards looking at each variable.
For example, what is Query?

And why have you now decided that the error occurs on teh line above where you originally claimed?
Member 11071167 11-Sep-14 4:27am    
thanks a lot for the help.. I found the solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900