日期:2014-05-19  浏览次数:20882 次

DS缺少using引用
SqlConnection   conn   =   new   SqlConnection( "data   source   =   data1;database   =   base1;   uid   =   sa;pwd   =   sa ");
SqlDataAdapter   da   =   new   SqlDataAdapter();
da.SelectCommand   =   new   SqlCommand( "select   *   from   admin ",conn);
conn.Open();
try
{
DataSet   ds   =   new   DataSet();
da.Fill(ds);
}
catch(Exception   ex)
{
throw   new   Exception(ex.Message);
}

for(int   i=0;i <ds.Tables[0].Rows.Count;i++)
{
}

提示for(int   i=0;i <ds.Tables[0].Rows.Count;i++)中的“ds”找不到类型或命名空间ds是否缺少using指令或程序集引用?

ds的值不是在:da.Fill(ds);这句赋值了吗?为什么有错误啊???


------解决方案--------------------
改成这样:
SqlConnection conn = new SqlConnection( "data source = data1;database = base1; uid = sa;pwd = sa ");
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand( "select * from admin ",conn);
conn.Open();

DataSet ds = new DataSet();

try
{

da.Fill(ds);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}

for(int i=0;i <ds.Tables[0].Rows.Count;i++)
{
}