简体   繁体   English

SQL查询未返回任何表。 怎么会这样

[英]No tables returned from a SQL query. How could that happen?

Im having an issue with the next code: 我对下一个代码有疑问:

try
        {
            OleDbConnection Conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database.accdb;Jet OLEDB:Database Password=LuzDary;");
            OleDbDataAdapter Data = new OleDbDataAdapter("SELECT * FROM Articulos", Conn);
            DataSet DSet = new DataSet();
            Conn.Open();
            Data.Fill(DSet);
            Conn.Close();
            _Articulos = DSet.Tables["Articulos"];
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

The try/catch is there because my VStudio 2010 installation isnt quite capable of detecting COM Exceptions somehow (Had the same issue creating the database with ADOX, the exception was uncaught, the code kept on running responsively somehow, but the DB was never written to the disk). 进行尝试/捕获是因为我的VStudio 2010安装程序不能够以某种方式检测到COM异常(使用ADOX创建数据库时遇到了同样的问题,未捕获到异常,代码仍以某种方式保持响应性运行,但是从未写入DB磁盘)。

The DB already has the "Articulos" table, and i manually inserted some records there, but if i foreach the DataSet, i only get a Table named "Table". 该数据库已经有“ Articulos”表,并且我在其中手动插入了一些记录,但是如果我获取数据集,则只能得到一个名为“ Table”的表。 This is getting frustrating now :( 现在,这令人沮丧:(

DSet.Tables[0].Rows is what you want. DSet.Tables [0] .Rows是您想要的。

This is what I mean. 这就是我的意思。

_Articulos = DSet.Tables[0];

With that, _Articulos.Rows should be populated with the records in your database. 这样,_Articulos.Rows应该用数据库中的记录填充。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从SQL查询字符串推断参数和返回的列? - How could I infer parameters & returned columns from a SQL query string? 在一个LINQ-to-Entities查询中限制来自多个表的结果。 结果T-SQL错误 - Limit results from multiple individual tables in a single LINQ-to-Entities query. Resultant T-SQL is wrong 如何“拆分”或优化Linq to Sql查询。 - How to “split up” or optimize a Linq to Sql query. 使用列名称的变量选择查询返回的列。 (asp.net C#) - Use a variable of the column names to select the column returned from a query. (asp.net c#) 我想获取我的查询返回的2个值。 如何使用linq-to-entity - I want to get 2 values returned by my query. How to do, using linq-to-entity 显示来自两个表的数据(无法在LINQ to Entities查询中构造。) - Display data from two tables (cannot be constructed in a LINQ to Entities query.) SQL参数化查询。 添加不必要的参数 - SQL parametrized query. Adding unnecessary parameters 解析查询时出错。 怎么解决呢? - There was an error parsing the query. How to resolve it? 如何将 else if 条件应用到 LINQ 查询中。? - How to apply the else if condition into the LINQ query.? 编辑从 SQL 查询返回的值 - Edit the values returned from an SQL Query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM