خطای Object reference not set to an instance of an object
با سلام
ببخشید من این برنامه رو نوشتم و این خطای بالارو می ده
مشخصا برنامه من
DataTable dt;x
SqlDataAdapter sqldap;x
DataSet dscon;x
private void Page_Load(object sender, System.EventArgs e)
{
}
this.Button1.
private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection sqlcon = new SqlConnection("server=(local);uid=sa;p wd=;database=lahijanbanktest");x
sqldap = new SqlDataAdapter("select * from phone",sqlcon);x
dscon = new DataSet();x
sqldap.Fill(dscon,"phone");x
this.DataGrid1.DataSource = dscon.Tables["phone"].DefaultView;x
this.DataGrid1.DataBind();x
}
private void Button2_Click(object sender, System.EventArgs e)
{
DataRow dr = dt.NewRow();x
dr["name"] = "Hamind";x
dr["lname"] = "Shrifi";x
dr["adres"] = "Kianshahr";x
dr["phonenumber"] = "3899147";x
dr["mail"] = "hamid_msc@yahoo.com";x
dr["www"] = "No Url";x
dt.Rows.Add(dr);x
this.DataGrid1.DataSource = dscon.Tables["phone"].DefaultView;
this.DataGrid1.DataBind();x
}
Source Error
نقل قول:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object
Line 66: private void Button2_Click(object sender, System.EventArgs e)
Line 67: {
[color=red]Line 68: DataRow dr = dt.NewRow();x[/color]
Line 69: dr["name"] = "Hamind";x
Line 70: dr["lname"] = "Shrifi";x
متشکر می شم اگه کمکم کنید
مرسی :oops: