数据未加载到网格中(发生不一致) [英] Data not loading in grid (occurring inconsistently )
问题描述
在生产服务器的网格中加载数据时,我发现以下脚本错误出现在页面左下角(此错误仅在生产服务器上发生,在本地服务器上正常运行)
此错误不一致地发生
网页错误详细信息
用户代理:Mozilla/4.0(兼容; MSIE 8.0; Windows NT 5.1; Trident/4.0; BTRS123646;嵌入式Web浏览器来自:http://bsalsa.com/; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)
时间戳记:星期二,2012年10月9日12:11:23 UTC
消息:未终止的字符串常量
专线:111115201
字符:187
代码:0
URI: http://Domain/MYApp/MyPage.aspx
以下是在网格中绑定数据的代码
While loading data in grid in production server I found following script Error on Page left bottom corner (This error is occurring only on production server, in local server its working fine)
This error is occurring inconsistently
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; BTRS123646; Embedded Web Browser from: http://bsalsa.com/; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)
Timestamp: Tue, 9 Oct 2012 12:11:23 UTC
Message: Unterminated string constant
Line: 111115201
Char: 187
Code: 0
URI: http://Domain/MYApp/MyPage.aspx
following is the code for binding data in grid
try
{
conGetPost.ConnectionString = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
conGetPost.Open();
SqlCommand cmdGetPost = new SqlCommand();
cmdGetPost.CommandTimeout = 999999999;
cmdGetPost.Connection = conGetPost;
cmdGetPost.CommandType = CommandType.StoredProcedure;
cmdGetPost.CommandText = "MySP";
if (wdpfrom.Value.ToString() == "1/1/0001 12:00:00 AM" || wdpTo.Value.ToString() == "1/1/0001 12:00:00 AM")
{
ShowMessage("Please select proper Date range");
wdgPost.DataSource = "";
wdgPost.DataBind();
return;
}
else
{
cmdGetPost.Parameters.AddWithValue("@dateFrom", wdpfrom.Value);
cmdGetPost.Parameters.AddWithValue("@dateTo", Convert.ToDateTime(wdpTo.Value.ToString()).Add(new TimeSpan(23, 59, 59)));
}
cmdGetPost.Parameters.AddWithValue("@ID", ID);
SqlDataAdapter daGetPost = new SqlDataAdapter();
daGetPost.SelectCommand = cmdGetPost;
daGetPost.Fill(dsGetPost);
if (dsGetPost.Tables.Count > 0)
{
if (dsGetPost.Tables[0].Rows.Count > 750)
{
ShowMessage("Maximum record found please reduce date range");
wdgPost.DataSource = "";
wdgPost.DataBind();
return;
}
}
wdgPost.ClearDataSource();
wdgPost.DataSource = dsGetPost;
wdgPost.DataBind();
if (dsGetPost.Tables[0].Rows.Count == 0)
{
ShowMessage("No records found");
}
Session["dsGetPost"] = dsGetPost;
}
catch( Exception ex)
{
return;
}
finally
{
if (conGetPost != null)
{
conGetPost.Close();
conGetPost = null;
}
}
如何知道我的C#代码中的行号?
如何解决?请帮助
How to know the line no in my C# code?
How to fix it? Please Help
推荐答案
我终于解决了.
我如何追踪?
启用脚本调试并使用了fiddler 2工具,发现出了什么问题.我发现在日期解析时抛出了一些错误.
我要解决什么?我写了一个用于日期时间转换的方法,如
Hi I finally solved it.
How I tracked it?
Enabling script debugging and used fiddler 2 tool and found whats going wrong. I found some error was thrown at date parsing.
What I did to solve? I wrote a method for datetime conversion as
public static bool ValidateDate(string txtDate, string sDateFormat, ref string sErrMsg, ref DateTime dtDate)
{
if (txtDate == "")
{
sErrMsg = "Please Enter Date";
return false;
}
else
{
System.Globalization.DateTimeFormatInfo dateInfo = new System.Globalization.DateTimeFormatInfo();
dateInfo.ShortDatePattern = sDateFormat;
try
{
dtDate = Convert.ToDateTime(txtDate, dateInfo);
return true;
}
catch
{
sErrMsg = "Please Enter Date In Correct Format";
return false;
}
}
}
然后我用作
then I used as
string errMsg = string.Empty;
Boolean IsFromDateValid = false;
DateTime fromDate = new DateTime();
IsFromDateValid = ValidateDate(wdpfrom.Text.Trim(), "dd/MM/yyyy", ref errMsg, ref fromDate);
if (IsFromDateValid == false)
{
ShowMessage(errMsg);
return;
}
Boolean IsToDateValid = false;
DateTime toDate = new DateTime();
IsToDateValid = ValidateDate(wdpTo.Text.Trim(), "dd/MM/yyyy", ref errMsg, ref toDate);
if (IsToDateValid == false)
{
ShowMessage(errMsg);
return;
}
else
{
TimeSpan ts = new TimeSpan(23, 59, 59);
toDate = toDate.Add(ts);
}
最后将参数作为
传递给SP
and finally passed parameter to SP as
cmdGetPost.Parameters.AddWithValue("@dateFrom", fromDate);
cmdGetPost.Parameters.AddWithValue("@dateTo", toDate);
这篇关于数据未加载到网格中(发生不一致)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!