C# 数据未加载到网格中(此错误不一致)
在生产服务器的网格中加载数据时,我在页面左下角发现了以下脚本错误。此错误仅发生在生产服务器上,在本地服务器上工作正常 此错误的发生不一致 网页错误详细信息 用户代理:与Mozilla/4.0兼容;msie8.0;windowsnt5.1;三叉戟/4.0;BTRS123646;嵌入式Web浏览器来自:。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:xyz/MYApp/MyPage.aspx 下面是在网格中绑定数据的代码C# 数据未加载到网格中(此错误不一致),c#,javascript,asp.net,sql-server-2008,iis-7,C#,Javascript,Asp.net,Sql Server 2008,Iis 7,在生产服务器的网格中加载数据时,我在页面左下角发现了以下脚本错误。此错误仅发生在生产服务器上,在本地服务器上工作正常 此错误的发生不一致 网页错误详细信息 用户代理:与Mozilla/4.0兼容;msie8.0;windowsnt5.1;三叉戟/4.0;BTRS123646;嵌入式Web浏览器来自:。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。NE
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代码中的行号?
如何修复它?请帮助尝试在两者之间添加BindingSource,如下所示:Control.DataSource=new BindingSourcesource 嗨,我终于解决了 我是怎么追踪的? 启用脚本调试并使用fiddler 2工具,发现了问题所在。我发现在日期解析时引发了一些错误 我是怎么解决的? 我写了一个日期时间转换的方法
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;
}
}
}
然后我用
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);
}
并最终将参数作为
cmdGetPost.Parameters.AddWithValue("@dateFrom", fromDate);
cmdGetPost.Parameters.AddWithValue("@dateTo", toDate);
Thanx用于回复,但BindingSource类位于System.Windows.Forms命名空间下。这是一个ASP.NET应用程序,所以无法完成。是不是生产服务器在发布模式下运行,而垃圾收集得太快了??我不知道dsGetPost返回的是什么类型,但我认为不应该将datasource设置为空字符串,而是应该清除dsGetPost Count=0中的列表并使用它设置datasource。