ADO.net 中如何编写C#代码,实现将sql数据库某个表的信息导出到记事本文档里面?在WINFORM下
用下面的代码连接数据库,因为是初学者,所以....(感谢了)using(SqlConnectionconn=newSqlConnection(@"DataSource=....
用下面的代码连接数据库,因为是初学者,所以....(感谢了)
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;
Integrated Security=True;User Instance=True;"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{ 展开
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;
Integrated Security=True;User Instance=True;"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{ 展开
展开全部
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;
Integrated Security=True;User Instance=True;"毁搭亩))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "纤森select * from 表名";
using(SqlDataReader rd = cmd.ExecuteReader())
using(StreamWriter sw = new StreamWriter(@"c:\枝液a.txt")){
while(rd.Read()){
sw.Write(rd[0]);
}
}
}
}
Integrated Security=True;User Instance=True;"毁搭亩))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "纤森select * from 表名";
using(SqlDataReader rd = cmd.ExecuteReader())
using(StreamWriter sw = new StreamWriter(@"c:\枝液a.txt")){
while(rd.Read()){
sw.Write(rd[0]);
}
}
}
}
追问
执行的时候,显示:“连接未关闭。 连接的当前状态为打开。”(我这段代码前没有别的代码啊!)
追答
哪一行显示这个错误呢?你可以评论里说一下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询