为什么Method无法使用数据集向数据库发送值?非静态字段,方法或属性(数据集)需要对象引用
实施例,错误
public string dane()
{
// Get the DataTable of a DataSet.
DataTable table = DataSet1.Tables["Products"];
DataRow[] rows = table.Select();
string s ="";
// Print the value one column of each DataRow.
for (int i = 0; i < rows.Length; i++)
{
s += rows[i]["ProductID"] + " ";
}
return s;
}
错误 - 一个对象引用是所必需的非静态字段,方法或属性
它`不可能找到数据。 (但错误被固定)
public string dane()
{
// Get the DataTable of a DataSet.
DataSet1 dataSet = new DataSet1();
DataTable table = dataSet.Tables["Products"];
DataRow[] rows = table.Select();
string s ="";
// Print the value one column of each DataRow.
for (int i = 0; i < rows.Length; i++)
{
s += rows[i]["ProductID"] + " ";
}
return s;
}
是的,但为什么我无法获得任何数据?使用第二个代码? – 2013-04-08 14:54:32
@ Rafael-JuniorMVCDeveloper你是否浏览过你的代码,并确认'rows'实际上包含任何东西,然后再执行'table.Select()'? – tnw 2013-04-08 14:59:56
它显示我我有0行,但在数据库中我有数据。 – 2013-04-08 15:01:46