c#winform怎样把数据库表中全部数据查询出来赋给richtextbox呢
2个回答
展开全部
SqlConnection conn = new SqlConnection(@"server=.;user=sa;password=123;database=数据采集");
conn.Open();
string sqlstr = "select * from min1 where 合约='CU**01' and 时间 between '2011-4-11 9:53:00' and '2011-4-15'";
DataSet ds=new DataSet();
SqlDataAdapter ada=new SqlDataAdapter(sqlstr,conn);
ada.Fill(ds);
DataTable dt = ds.Tables[0];
StringBuilder sb = new StringBuilder(textBox1.Text);
string str = "";
foreach (DataRow dr in dt.Rows)
{
for (int i = 0; i < dt.Columns.Count; i++)
{
str += dr[i].ToString()+" ";
}
sb.Append(str+"\r\n");
str = "";
}
richtextbox.Text = sb.ToString();
SQL语句改成你需要的,你看看,大概是这样子的
conn.Open();
string sqlstr = "select * from min1 where 合约='CU**01' and 时间 between '2011-4-11 9:53:00' and '2011-4-15'";
DataSet ds=new DataSet();
SqlDataAdapter ada=new SqlDataAdapter(sqlstr,conn);
ada.Fill(ds);
DataTable dt = ds.Tables[0];
StringBuilder sb = new StringBuilder(textBox1.Text);
string str = "";
foreach (DataRow dr in dt.Rows)
{
for (int i = 0; i < dt.Columns.Count; i++)
{
str += dr[i].ToString()+" ";
}
sb.Append(str+"\r\n");
str = "";
}
richtextbox.Text = sb.ToString();
SQL语句改成你需要的,你看看,大概是这样子的
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |