读书人

DS缺少using引用解决方案

发布时间: 2012-01-23 21:57:28 作者: rapoo

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++)
{
}

读书人网 >C#

热点推荐