我已經使用MSDN的示例向我的DataSet添加新記錄。我甚至使用了相同的變量名來保持簡單。將新記錄添加到輸入的數據集錯誤
C#代碼
NorthwindDataSet.CustomersRow newCustomersRow =
northwindDataSet1.Customers.NewCustomersRow();
newCustomersRow.CustomerID = "5";
newCustomersRow.CompanyName = "Alfreds Futterkiste";
northwindDataSet1.Customers.Rows.Add(newCustomersRow);
我得到的錯誤是The name 'northwindDataSet1' does not exist in the current context
我覺得這很奇怪,因爲我直接使用的代碼從MSDN。
我的DataSet被稱爲NorthwindDataSet,該表稱爲Customers。我試過northwindDataSet
但仍然是一樣的錯誤。
你明明沒有申報'northwindDataSet1'在你的代碼,至少不會在適當的水平。 – hattenn 2013-05-10 11:03:43
在這段代碼中我沒有定義northwindDataSet1 – 2013-05-10 11:04:17
(這與ASP.NET無關 - 我更改了標籤以反映它更多地使用ADO.NET。) – 2013-05-10 11:08:18