DataTable dt = ds.tables[quot;putquot;]; why #39;dt#39; is null?(DataTable dt = ds.tables[“put];为什么dt为空?)
问题描述
string sel = "select * from PUTIN";
DataSet ds = new DataSet();
DataTable dt = ds.Tables["put"];
DataRow row = dt.NewRow();
这是代码.当我运行 DataRow row = dt.NewRow(); 行时我得到一个例外:
This is the code. When I run the line DataRow row = dt.NewRow();
 I get an exception:
对象引用未设置为对象的实例
Object reference not set to an instance of an object
我发现 dt 为空,为什么以及如何解决它?
I find dt is null, why and how to slove it?
推荐答案
您的 DataSet 目前为空.您需要使用 SqlDataAdapter 在这里填写您的 DataSet.像这样:
Your DataSet is empty currently. You need to use a SqlDataAdapter here to fill your DataSet. Like this:
string sel = "select * from PUTIN";
SqlDataAdapter da = new SqlDataAdapter(sel,connection);
DataSet ds = new DataSet();
da.Fill(ds,"put");
DataTable dt = ds.Tables["put"];
DataRow row = dt.NewRow();
                        这篇关于DataTable dt = ds.tables[“put"];为什么'dt'为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:DataTable dt = ds.tables[“put"];为什么'dt'为空?
				
        
 
            
        - C# 中多线程网络服务器的模式 2022-01-01
 - 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
 - 输入按键事件处理程序 2022-01-01
 - 如何用自己压缩一个 IEnumerable 2022-01-01
 - Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
 - C#MongoDB使用Builders查找派生对象 2022-09-04
 - 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
 - MoreLinq maxBy vs LINQ max + where 2022-01-01
 - 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
 - WebMatrix WebSecurity PasswordSalt 2022-01-01
 
						
						
						
						
						
				
				
				
				