C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\WebApplicationKflash\Db\Sort.cs(197): 名称“dv”在类或命名空间“Db.Sort”中不存在=======================================================> public DataView dgBigSortBind()//绑定数据到大类DataGrid
{
conn = new SqlConnection(ConfigurationSettings.AppSettings["dsn"]);
da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand("Sp_Kflash_BigSort_SelectAll",conn);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Open();
try
{
da.SelectCommand.ExecuteNonQuery();
DataView dv = new DataView();
dv = ds.Tables[0].DefaultView;
}
catch(Exception e)
{
Console.Write(e.Message);
}
finally
{
conn.Dispose();
conn.Close();
} return dv;
}

解决方案 »

  1.   

    按道理应该是System.Data;可是我这种写法却老是提示dv不存在,我明明在上面已经定义了啊。
    public DataView dgBigSortBind()//绑定数据到大类DataGrid
    {
    conn = new SqlConnection(ConfigurationSettings.AppSettings["dsn"]);
    da = new SqlDataAdapter();
    da.SelectCommand = new SqlCommand("Sp_Kflash_BigSort_SelectAll",conn);
    da.SelectCommand.CommandType = CommandType.StoredProcedure;
    DataSet ds = new DataSet();
    da.Fill(ds);
    conn.Open();
    try
    {
    da.SelectCommand.ExecuteNonQuery();
    DataView dv = new DataView();
    dv = ds.Tables[0].DefaultView;
    }
    catch(Exception e)
    {
    Console.Write(e.Message);
    }
    finally
    {
    conn.Dispose();
    conn.Close();
    } return dv;
    }
      

  2.   

    System.Data.DataViewadd a reference to System.Data.dlland add the following line at the top of your fileusing System.Data;
      

  3.   

    问题已经解决,与原来我是把dv定义在try里面,要定义在try上面才可以。
      

  4.   

    move DataView dv = new DataView();to the outer level
    public DataView dgBigSortBind()//绑定数据到大类DataGrid
    {
    DataView dv = null; conn = new SqlConnection(ConfigurationSettings.AppSettings["dsn"]);
    da = new SqlDataAdapter();
    da.SelectCommand = new SqlCommand("Sp_Kflash_BigSort_SelectAll",conn);
    da.SelectCommand.CommandType = CommandType.StoredProcedure;
    DataSet ds = new DataSet(); conn.Open(); da.Fill(ds);


    dv = ds.Tables[0].DefaultView;

    conn.Dispose();

    return dv;
    }