2014-09-11 29 views
0

的雙數據類型,我的代碼背後的GridView的數據綁定:字符串轉換爲GridView的列

protected void PumpGridBind() 
{ 
    string name = Request.QueryString[1].ToString(); 
    string query = "select q1.ID , q1.Scenario, q1.Type, q1.StationName ,q1.minH, 
    q1.maxH ,q1.Station_Id, q1.Min_OL, q1.Max_OL, q2.Daily_Abstraction as Action 
    from  
    (select SD.id,SD.Scenario,PR.Type,PR.StationName,max(if(PARAM = 'minH', Value, ' 
    -999.00')) 
    as 'minH',max(if(PARAM = 'maxH', Value, ' -999.00'))  
    as 'maxH',psd.Station_Id,psd.Min_OL,psd.Max_OL from sgwebdb.param_reference as PR 
    Inner 
    join 
    sgwebdb.scenario_data as SD ON PR.Param_Id = SD.Param_Id INNER JOIN 
    sgwebdb.qualicision_detail as Q ON SD.SCENARIO = Q.Alternative INNER JOIN 
    sgwebdb.pump_station_detail as psd ON psd.Station_Id = PR.Station_Id where PR.Type 
    = 'Pump' and Q.Alternative = '" + name + "' GROUP BY PR.Id) q1 JOIN (SELECT 
    t1.Daily_Abstraction ,t1.Station_id FROM sgwebdb.pump_station_data t1 INNER JOIN 
    (SELECT 
    Station_id, MAX(lastupdate) as lastupdate FROM sgwebdb.pump_station_data GROUP BY 
    Station_id) t2 ON t1.Station_id = t2.Station_id AND t1.lastupdate = t2.lastupdate) 
    q2 on 
    q1.Station_Id=q2.Station_Id"; 

    this.GridView2.DataSource = PSI.DataAccess.Database.DatabaseManager.GetConnection 
    ().GetData(query); 
    GridView2.DataBind(); 

    } 

這裏GridView的列胡志明市即將爲一個字符串。 在與gridview綁定之前,我們可以將字符串轉換爲Double嗎?

回答

0

可以使用

string query = "select q1.ID , q1.Scenario, q1.Type, q1.StationName ,**CAST(q1.minH as DECIMAL(9,2)) q1.minH** 
+0

解決方案 - MSTeam這是正確的語法CAST(q1.minH十進制(9,2))q1.minH – vim 2014-09-11 10:06:51

+0

是。你有沒有發現什麼問題?請提一下。 – 2014-09-11 10:12:07