本文介绍了为什么我没有将对象引用设置为对象错误的实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 这里我的代码是 PresentationLayer: Here My code isPresentationLayer:using BusinessAccessLayer;namespace _3_tiermahesh{ public partial class PresentationLayer : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Gridview1.DataSource = Objbll.ReturnGridViewData(); } ClsBLL Objbll = new ClsBLL(); protected void btnsave_Click(object sender, EventArgs e) { try { Objbll._Name = TextBox1.Text; Objbll._Address = TextBox2.Text; Objbll._EmailID = TextBox3.Text; Objbll._Mobilenumber = TextBox4.Text; Objbll.InsertRecord(); Console.WriteLine("Record Is Inserted Don't Worrry"); } catch(Exception Ex) { Console.WriteLine(Ex); } } }} BusinessLogicLayer: BusinessLogicLayer:using System.Data;using DataAccessLayer;namespace BusinessAccessLayer{ public class ClsBLL { string Name, Address, EmailID, Mobilenumber; DataRow Rec; ClsDAL objdal = new ClsDAL(); public string _Name { set { Name = value; } get { return Name; } } public string _Address { set { Address = value; } get { return Address; } } public string _EmailID { set { EmailID = value; } get { return EmailID; } } public string _Mobilenumber { set { Mobilenumber = value; } get { return Mobilenumber; } } public void InsertRecord() { Rec = objdal.Ds.Tables[0].NewRow(); Rec[0] = Name; Rec[1] = Address; Rec[2] = EmailID; Rec[3] = Mobilenumber; objdal.Ds.Tables[0].Rows.Add(Rec); } public object ReturnGridViewData() { return objdal.Ds.Tables[0];//Here Iam getting the Exception Message as above mentioned. } } DataAccessLayer: DataAccessLayer:using System.Data;using System.Data.SqlClient;using System.Configuration;namespace DataAccessLayer{ public class ClsDAL { SqlConnection Con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()); SqlDataAdapter Da; public DataSet Ds; SqlCommandBuilder bldr; public void clsDalEmployeeDetails() { Da = new SqlDataAdapter("Select * from Userinfo", Con); Ds = new DataSet(); Da.Fill(Ds, "Userinfo"); Da.FillSchema(Ds, SchemaType.Source, "Userinfo"); bldr = new SqlCommandBuilder(Da); } public void UpdateDB() { Da.Update(Ds,"Userinfo"); } }}} 帮帮我谢谢你 并给一些关于我编写的代码和相同格式的建议是否会实时使用?我的意思是使用Rec对象来使用插入记录。Help me Out Thankyouand give some suggestions about the code i have written and the same format will be used in real time or not? i mean using Rec object to use inserting Records.推荐答案 datatable dt = new datatable();dt = null;var a = dt.rows[0][0].tostring();//now ull get this error 有很多像这样的实例会出现这个错误。there are lot of instances like this where ull get this error. 这篇关于为什么我没有将对象引用设置为对象错误的实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-18 21:34