检索数据集(本地主机上没有错误,但在线错误) [英] Retrieving a dataset (no error on localhost but error online)

查看:76
本文介绍了检索数据集(本地主机上没有错误,但在线错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

dsData = Data.GetDataSet(sqlData, GlobalParameters.conn)
            For Each dr As DataRow In dsData.Tables(0).Rows



由于某些原因(我完全毫无头绪),以上几行在我在localhost上运行站点时工作正常,但在上载到服务器时却行不通.即使sql查询正确(并且已经过测试),由于某种原因它也会出现以下错误消息

System.IndexOutOfRangeException: Cannot find table 0. at System.Data.DataTableCollection.get_Item(Int32 index) at Website.AdAppointments.btnSendAppointments_Click(Object sender, EventArgs e) in (FILE LOCATION):line 224

第224行是For循环的开始.

非常感谢:)



The lines above, for some reason (I''m completely clueless) work perfectly when I''m running the site on localhost, but it won''t work when uploaded onto a server. it for some reason comes up with the following error message even though the sql query is correct (and its been tested)

System.IndexOutOfRangeException: Cannot find table 0. at System.Data.DataTableCollection.get_Item(Int32 index) at Website.AdAppointments.btnSendAppointments_Click(Object sender, EventArgs e) in (FILE LOCATION):line 224

Line 224 is the beginning of the For loop.

Thanks a lot :)

推荐答案

由于未返回任何结果,它可能试图将数据表绑定到没有表的数据集.

在使用数据表之前,请检查其是否存在:
It is probably trying to bind a data table to a dataset which does not have a table because no results were returned.

before using the datatables check for its existance:
if (DataSet1.Tables.Count > 0)


System.IndexOutOfRangeException:在
上找不到表0. 此错误与服务器或本地环境无关.这很简单,它意味着返回的数据集没有表,因此当您尝试访问表(假设有表)时,它将引发错误.

不过,已经建议您在使用表之前先检查一下该表是否存在.此外,仅考虑任何环境因素,可能是连接字符串不正确(错误)并且数据集未正确返回/形成,因此您将面临错误.只需确保在本地环境中返回了数据,然后就可以了.
System.IndexOutOfRangeException: Cannot find table 0. at
This error has nothing to do with server or local environment. It simple means that the dataset returned has no tables and thus when you try to access a table(assuming it is there), it throws an error.

Though, it''s already suggested that make sure you check if the table exists or not before using it. Further, just considering any environemnt thing, it might be that the connection string is not proper(is wrong) and the dataset is not returned/formed correctly and thus you face an error. Just make sure that the data is returned as in local environment and then it should be fine.


数据集未返回值.可能是检查您的数据库连接字符串是否指向wright数据库.
The dataset is not returning values. May be check your database connection string whether it points to the wright database.


这篇关于检索数据集(本地主机上没有错误,但在线错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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