开发者

How to get the DataSourceId?

开发者 https://www.devze.com 2023-03-02 21:29 出处:网络
private SqlDataSource GetDataSource() { object o = Session[\"selectedDataSource\"]; DataSourceType dsType = DataSourceType.Gtable;
private SqlDataSource GetDataSource()
       {

           object o = Session["selectedDataSource"];
           DataSourceType dsType = DataSourceType.Gtable;            

              if (o != null)
                   dsType = (DataSourceType)o;

              switch (dsType)
              {
                  case DataSourceType.tableT:
                      return DataSourceTID;
                  case DataSourceType.tableR:
                      return DataSourceRID;
                  case DataSourceType.tableC:
              开发者_运维知识库        return DataSourceCID;
                  default:
                      return DataSourceCID;
              }        
       }

For getting the datasourceid I wrote that code.But that gives the error as "Specified cast is not valid".This error is arise at dsType=(DataSourceType)o line. Please give me any suggextions.


Use enum parse method

http://msdn.microsoft.com/en-us/library/essfb559.aspx

DataSourceType dsType = (DataSourceType) Enum.Parse(typeof(DataSourceType), o);
0

精彩评论

暂无评论...
验证码 换一张
取 消