int i;
string aaa;
for( i=0;i<DataSet.Table[0].Rows.Count;i++ )
{
aaa = DataSet.Table[0].Rows[i]["字段"].ToString();
}
string aaa;
for( i=0;i<DataSet.Table[0].Rows.Count;i++ )
{
aaa = DataSet.Table[0].Rows[i]["字段"].ToString();
}
string str="";
string strSQL="SELECT A1 FROM Table WHERE ID='123';
string connStr=("你的连接字符串");
conn=new SqlConnection(connStr);
SqlCommand cmd=new SqlCommand(strSQL,conn);
str=cmd.ExecuteScalar().ToString();//ExecuteScalar()返回结果集的第一行第一列。返回的是一个object类型的类型,所以要转换成字符串。
用嵌套循环遍历
从MSDN摘的:
Dim custView As DataView = New DataView(custDS.Tables("Customers"), "", _
"CompanyName", DataViewRowState.CurrentRows)Dim rowIndex As Integer = custView.Find("The Cracker Box")If rowIndex = -1 Then
Console.WriteLine("No match found.")
Else
Console.WriteLine("{0}, {1}", _
custView(rowIndex)("CustomerID").ToString(), _
custView(rowIndex)("CompanyName").ToString())
End If
[C#]
DataView custView = new DataView(custDS.Tables["Customers"], "",
"CompanyName", DataViewRowState.CurrentRows);int rowIndex = custView.Find("The Cracker Box");if (rowIndex == -1)
Console.WriteLine("No match found.");
else
Console.WriteLine("{0}, {1}",
custView[rowIndex]["CustomerID"].ToString(),
custView[rowIndex]["CompanyName"].ToString());
end if