
C# 怎样把数据库中的多张表一次性的存进同一个DataSet里面
publicDataSetDS(){stringsql=@"selectnamefromsysobjectswherextype='"+"U'";SqlDataAdapt...
public DataSet DS()
{
string sql = @"select name from sysobjects where xtype='" + "U'";
SqlDataAdapter sda = new SqlDataAdapter(sql,Sc);
DataSet ds = new DataSet();
sda.Fill(ds);
foreach (DataRow dr in ds.Tables[0].Rows)
{
string tablename = @"select * from " + dr[0];
}
return ds;
}
这样再怎么做?注意是把数据库的多张表存进dataset里面,是多张表存进同一个dataset里面 展开
{
string sql = @"select name from sysobjects where xtype='" + "U'";
SqlDataAdapter sda = new SqlDataAdapter(sql,Sc);
DataSet ds = new DataSet();
sda.Fill(ds);
foreach (DataRow dr in ds.Tables[0].Rows)
{
string tablename = @"select * from " + dr[0];
}
return ds;
}
这样再怎么做?注意是把数据库的多张表存进dataset里面,是多张表存进同一个dataset里面 展开
展开全部
其实这也很简单,方法如下:
1、动态操作DataSet:简单的说,先给DataSet创建几个table,然后修改sda.Fill(ds);中的ds到其中的具体表,注意这时的sql语句是每次选取一个表;
2、如果想一次性把多个表存储到DataSet中,可以通过存储过程,在存储过程中多写几条select就行了
希望能帮到你 ^-^
1、动态操作DataSet:简单的说,先给DataSet创建几个table,然后修改sda.Fill(ds);中的ds到其中的具体表,注意这时的sql语句是每次选取一个表;
2、如果想一次性把多个表存储到DataSet中,可以通过存储过程,在存储过程中多写几条select就行了
希望能帮到你 ^-^
追问
代码如何写?
展开全部
string sql = @"select * from student
select * from teacher
select * from score";
SqlDataAdapter sda = new SqlDataAdapter(sql,Sc);
DataSet ds = new DataSet();
sda.Fill(ds);
DataTable t1=ds.Tables[0];//student表
DataTable t2=ds.Tables[1];//teacher表
DataTable t3=ds.Tables[2];//score表
return ds;
select * from teacher
select * from score";
SqlDataAdapter sda = new SqlDataAdapter(sql,Sc);
DataSet ds = new DataSet();
sda.Fill(ds);
DataTable t1=ds.Tables[0];//student表
DataTable t2=ds.Tables[1];//teacher表
DataTable t3=ds.Tables[2];//score表
return ds;
追问
问题是如果100张表,你不能写100个sql语句的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |