在生产服务器中的网格中加载数据时,我在左下角的页面上找到以下脚本错误(此错误仅在生产服务器上发生,在本地服务器上运行正常)
 此错误发生不一致

网页错误详细信息

用户代理: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

消息:未终止的字符串常量
线:111115201
字符:187
代码:0

URI:XYXZ / MYApp / MyPage.aspx

以下是在网格中绑定数据的代码

 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 BindingSource(source,“”);

关于c# - 数据未加载到网格中(此错误不一致地发生),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12800638/

10-12 12:57
查看更多