关于asp.net:{“对象引用未设置为对象的实例。“}

{“Object reference not set to an instance of an object.”}

用C_创建一个ASP.NET窗体,我面临着这个错误,我不知道它有什么错误。一切正常,但当我按下"保存"按钮时,会出现以下错误:

1
2
3
     NulllRefrenceException was unhandled BY USER code
    {"Object reference not set to an instance of an object."}
Object reference NOT SET TO an instance OF an object.

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
     protected void Button8_Click(object sender, EventArgs e)
    {
         SqlConnection cnn = NEW SqlConnection();
         cnn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["sqlAddSave"].ConnectionString;
    cnn.Open();
    SqlCommand cmd = NEW SqlCommand();
    cmd.CommandText ="select * from  DisplayPP";
    cmd.Connection = cnn;
    SqlDataAdapter da = NEW SqlDataAdapter();
    da.SelectCommand = cmd;
    DataSet ds = NEW DataSet();
    da.Fill(ds," DisplayPP");
    SqlCommandBuilder cb = NEW SqlCommandBuilder(da);
    DataRow drow = ds.Tables["DisplayPP"].NewRow();
    drow["website"] = web.Text;
    drow["country"] = DropDownList1.SelectedItem.Text;
    drow["contact"] = TextBox144.Text;
    drow["cat"] = TextBox145.Text;
    drow["traff"] = TextBox146.Text;

    more text boxes AS above

    ds.Tables["DisplayPP"].Rows.Add(drow);
    da.Update(ds," DisplayPP");
    string script = @"<script language=""javascript"">
    alert('Information have been Saved Successfully.......!!!!!.');
   ;"
;
    Page.ClientScript.RegisterStartupScript(this.GetType(),"myJScript1", script);
    }

请帮助。

连接字符串:

1
2
<ADD name="sqlAddSave" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\PPTableDisplay.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />

例外

Exception Details: System.NullReferenceException was unhandled by user
code HResult=-2147467261 Message=Object reference not set to an
instance of an object. Source=TestCRole StackTrace: at
TestCRole._Default.Button8_Click(Object sender, EventArgs e) in
c:\Users\xxxxx\Documents\Visual Studio
2012\Projects\WindowsAzure2\TestCRole\Default.aspx.cs:line 60 at
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:


1
ds.Tables["DisplayPP"].Rows.Add(drow);

应该是这样的 </P >

1
ds.Tables["DisplayPP"].Rows.Add(drow);