对象实例未设置为对象的实例c# [英] object instance not set to an instance of an object c#

查看:82
本文介绍了对象实例未设置为对象的实例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();







对象实例未设置为对象的实例c#



TextBoxID.Text = ds.Tables [Tbl_JobseekerPersonalDetails]。行[0] [JobseekerID]。ToString();




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

TextBoxID.Text = ds.Tables["Tbl_JobseekerPersonalDetails"].Rows[0]["JobseekerID"].ToString();

推荐答案

我们无法分辨 - 我们无法查看,因为我们无权访问您的查询或您的数据。



有四种基本可能性:

1)您的查询不返回名为的表格Tbl_JobseekerPersonalDetails

2)您的查询返回表,但表中没有行

3)您的查询返回表,它有行,但没有名为 JobseekerID

4)您的查询返回表,它有行,并且有一列,但 TextBoxID 为空。



这取决于你:使用调试器,在问题发生时查看代码并找出其中的哪一个。

如果你不能使用调试器,那么你需要学习,但你可以通过分割线来帮助找出:

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:
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.


这篇关于对象实例未设置为对象的实例c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆