数据集给出了错误的记录 [英] dataset giving wrong records

查看:74
本文介绍了数据集给出了错误的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

填充数据集后,它还会在数据集中显示旧值。

这个问题有时会出现,但是在上传web.config后它会在数据集中显示正确的数据。

网站在旧的iis上工作正常但是当我们将它转​​移到iis 7时这个问题就开始了。



请尽快回复我,谢谢提前



不是每个页面都有页面它给出错误,因为它提供了一些奇怪的数据,而不是从给定的sql中获取数据。

代码:



after filling dataset then also it shows old values in dataset.
This problem arises sometimes but after uploading web.config it shows proper data in dataset.
Site working fine on old iis but when we shifted it to iis 7 this problem started.

please answer me as soon as possible thanks in advance

not just on one page on every page it gives error because it is giving some weird data and not taking data from given sql.
code:

       SqlConnection con1 = new SqlConnection("connction" );
        DataSet temp = new DataSet();
        SqlCommand temp1 = new SqlCommand();
        SqlDataAdapter temp2;
        ds = new DataSet();
        int bcnt = 0, rcnt = 0;
        ds = null;
        ds = new DataSet(); string col = string.Empty;
        temp1 = new SqlCommand("select image, linkto, desiredwidth from ( select image, linkto, desiredwidth from pbdetail, userbanner where pbdetail.userbannerid=userbanner.userbannerid and pagebannerid=1 and disp=1 and (pbdetail.awaiting =0 or pbdetail.awaiting is null) union select image, linkto, desiredwidth from pbdetail where pbdetail.userbannerid=0 and pagebannerid=1 and disp=1 and (pbdetail.awaiting =0 or pbdetail.awaiting is null) )q1 order by newid() ", con1);
        temp2 = new SqlDataAdapter(temp1);
        temp2.Fill(temp);
 if (temp.Tables[0].Rows.Count > 0)
        {
for (int i = 0; i <= rcnt; i++)
            {

                string x = "banner" + i.ToString();
                Image banner = (Image)FindControl(x);
                string str = ds.Tables[0].Rows[i]["image"].ToString();//error on this line image column not exist
                if (str.StartsWith("u") == true)
                {
                    banner.ImageUrl = ds.Tables[0].Rows[i]["image"].ToString();
                }
                else
                {
                    banner.ImageUrl = "uploads/" + ds.Tables[0].Rows[i]["image"].ToString();
                }
                HtmlAnchor linkto = (HtmlAnchor)FindControl("linkto" + i.ToString());
                linkto.HRef = "http://" + ds.Tables[0].Rows[i]["linkto"].ToString() + "";
               
            }
}





[edit]已添加代码块 - OriginalGriff [/ edit]



[edit]Code block added - OriginalGriff[/edit]

推荐答案

循环 rcnt ,初始化为 0 的。您没有为 rcnt 设置任何值。您需要交叉检查并查看未分配的原因。 rcnt 的值始终为 0 。您可能忘记设置 rcnt 的值。调试你的代码并检查它。





--Amit
You are looping through rcnt which is initialized to 0. You are not setting any value for rcnt. You need to cross check it and see why it is not assigned. The value of rcnt will be 0 always. You might be forgetting to set the value for rcnt. Debug your code and check it.


--Amit


这篇关于数据集给出了错误的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆