各位高手,想问这样的一个问题
鉴于上次通过js把时间隔的问题给显示出来的
现在想从数据表中读取出每段时间隔的降雨量
其中代码如下
类型:
Water_DAL.cs
1 #region 河道 2 public static string[] GetHDSingleTimeAdd(DateTime time, string code) 3 { 4 DbHelperSQLP db = new DbHelperSQLP(); 5 db.connectionString = PubConstant.GetConnectionString("Conn_WaterRain"); 6 string Sql = string.Format("select top 1 STCDT,YMDHM,ZR,ZRTEND from ST_RIVER_R where STCDT='{0} and YMDHM<='{1}' and YMDHM='{2}' order by YMDHM desc", code, time.ToString(), time.AddHours(-1).ToString()); 7 DataTable Water = db.Query(Sql).Tables[0]; 8 if (Water.Rows.Count != 0) 9 { 10 DateTime YMDHM = Convert.ToDateTime(Water.Rows[0]["YMDHM"]); 11 int hour = YMDHM.Hour; 12 int minute = YMDHM.Minute; 13 return new string[] { Water.Rows[0]["ZR"].ToString().Trim(), (hour < 10 ? "0" + hour.ToString() : hour.ToString()) + ":" + (minute < 10 ? "0" + minute.ToString() : minute.ToString()) }; 14 } 15 else 16 { 17 return new string[] { "", "" }; 18 } 19 }#region
Water_BLL.cs
1 public static string[] GetHDSingeTimeAdd(DateTime time, string code) { 2 return DAL.Water_DAL.GetHDSingleTimeAdd(time, code); 3 }
WebService.asmx
1 public DataTable GetWaterInfoList(string tm,string search) 2 { 3 DateTime time = Convert.ToDateTime(tm); 4 time = new DateTime(time.Hour); 5 DataTable sites = BLL.Site_BLL.GetWaterSitesTable(search); 6 sites.Columns.Add("zgsw", typeof(string)); 7 sites.Columns.Add("zdsw", typeof(string)); 8 sites.Columns.Add("time", typeof(string)); 9 if (sites.Rows.Count != 0) 10 { 11 for (int i = 0; i < sites.Rows.Count; i++) 12 { 13 sites.Rows[i]["area2"] = BLL.Areainfo_BLL.GetAreaName(sites.Rows[i]["area2"].ToString().Trim()); 14 if (sites.Rows[i]["sttp"].ToString().Trim() == "1") 15 { 16 string[] temp = BLL.Water_BLL.GetHDSingeTimeAdd(time, sites.Rows[i]["code"].ToString().Trim()); 17 sites.Rows[i]["zgsw"] = temp[0]; 18 sites.Rows[i]["zdsw"] = temp[1]; 19 sites.Rows[i]["time"] = temp[2]; 20 } 21 if (sites.Rows[i]["sttp"].ToString().Trim() == "2") 22 { 23 string[] temp1 = BLL.Water_BLL.GetSKSingleTimeAdd(time, sites.Rows[i]["code"].ToString().Trim()); 24 sites.Rows[i]["zgsw"] = temp1[0]; 25 sites.Rows[i]["zdsw"] = temp1[1]; 26 sites.Rows[i]["time"] = temp1[2]; 27 } 28 } 29 } 30 return sites; 31 }
function CallbackData(val) { var conArr = []; var html = ""; if (val != undefined && val != null) { if (val.rows != null) { for (var i = 0; i < val.rows.length; i++) { html+="<table border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" borderColorLight=\"#009999\" borderColorDark=\"#ffffff\" bgColor=\"#DAEBF8\" style=\"font-size:12px;\">"; html+="<tr style=\"Font:9pt\">"; html+="<td height=\"20\" width=\"80\" align=\"center\">" + val.rows[i].name.trim() + "</td>"; html += "<td height=\"20\" width=\"75\" align=\"center\">" + (val.rows[i].sttp == "1" ? "河道" : (val.rows[i].sttp == "2" ? "水库" : "")) + "</td>"; html += "<td height=\"20\" width=\"63\">" + (val.rows[i].zgsw == "" ? "--" : val.rows[i].zgsw) + "</td>"; html+="<td height=\"20\" width=\"57\" ></td>"; html+="<td height=\"20\" width=\"79\" ></td>"; html+="<td height=\"20\" width=\"62\"></td>"; html+="<td height=\"20\" width=\"79\"></td>"; html+="<td height=\"20\" width=\"61\"></td>"; html+="<td width=\"61\"></td>"; html+="<td width=\"60\"></td>"; html+="<td width=\"78\"></td>"; html+="<td height=\"20\" width=\"79\"></td> "; html+="<td width=\"77\"></td>"; html+="<td height=\"20\" width=\"102\"></td>"; html+="</tr>"; html+="</table>"; } } } document.getElementById("table").innerHTML = html; }
整体上是这样的,通过客户端来读取数据的,现在数据显示不了,请帮忙看看!
你在什么地方调用GetWaterInfoList,给页面上的table赋值的呢
高手,可以扣扣问你吗?我的QQ是的843366285。谢谢了。在线等....
@doubledu: 工作时间不怎么用QQ,这样吧,你把服务器端返回的datatable数据(用firebug等工具监测)发出来,我再看看代码中的问题是什么
@artwl: 我现在在webservice.asmx.cs里面这样写代码:
[WebMethod] public void GetWaterInfoList(string tm,string search) { //DateTime time = Convert.ToDateTime(tm); //time = new DateTime(time.Hour); DataTable result = new DataTable(); DataTable sites = BLL.Site_BLL.GetWaterSitesTable(search); result.Columns.Add("测站", typeof(String)); result.Columns.Add("类型", typeof(String)); DateTime time = Convert.ToDateTime(tm); result.Columns.Add(time.Hour.ToString(), typeof(String)); for (int i = 0; i < 12; i++) { result.Columns.Add((time.Hour - i - 1).ToString() + "-" + (time.Hour - i).ToString(), typeof(String)); } for (int i = 0; i <sites.Rows.Count; i++)//取出来的测站 { DataRow dr = result.NewRow(); dr["测站"]=sites.Rows[i]["name"].ToString(); foreach (DataColumn dc in result.Columns)//result列 { if (dc.ColumnName != "测站" || dc.ColumnName!="类型") { if (dc.ColumnName.IndexOf('-') >-1) { string str = dc.ColumnName.Split('-')[1].ToString(); } dr[dc.ColumnName] = result.Columns.Add((time.Hour - i - 1).ToString() + "-" + (time.Hour - i).ToString(), typeof(String)); } } } }
通过做循环循环出来,看看哪里有错没。数据显示不了。
@doubledu: webservice中估计没什么问题,很可能是js中的问题,你是什么时候调用CallbackData的?
@artwl: 大侠,可以加下QQ吗?谢谢了!有好多要问,在博问里一时半会问不清。thxs.