关于DataAdapter填充非框架数据集DataSet

Manonloki 2010-10-13 09:37:22


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace DataAdapterDemo
{
public class SQLAccess
{
private static SqlConnection conn = new SqlConnection(@"server=.\SQLExpress;database=AdapterDemo;Trusted_Connection=SSPI");
private SqlDataAdapter sda = new SqlDataAdapter();
private DataSet ds = null;

public DataSet getDataSet()
{
try
{
conn.Open();
SqlCommand selectCommand = new SqlCommand("select * from Demo", conn);

sda.SelectCommand = selectCommand;
sda.Fill(ds);
return ds;
}
catch
{
return null;
}
finally
{
conn.Close();
conn.Dispose();
sda.Dispose();
}
}
}
}




代码如上 但是报错 "值不能为空。\r\n参数名: dataSet"

请问如何解决……
...全文
61 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
gagahjt8 2011-06-27
  • 打赏
  • 举报
回复
kankan jiejeu fangan
一切为了你 2010-10-13
  • 打赏
  • 举报
回复
DataSet ds =new DataSet();

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧