我一直在努力,仍然不知道如何解决这个问题,不断得到同样的错误。我想从数据库中获取数据到txt文件。
using (conn)
{
conn.Open();
SqlCommand cmd = new SqlCommand(command)
cmd.Connection = (SqlConnection)conn;
using (cmd)
{
SqlDataReader reader = cmd.ExecuteReader();
using(reader)
{
while (reader.Read())
{
dt.Load(reader);
}
}
using (StreamWriter sw = new StreamWriter(txtPath.Text + fileName))
{
// write to text file from Datatable dt
} }
答案 0 :(得分:2)
尝试输入您的代码,如下所示:
DataTable myDataTable = new DataTable();
using (SqlConnection myConnection = new SqlConnection(yourDBconn)
{
yourDBconn.Open();
using (SqlDataAdapter myAdapter = new SqlDataAdapter(strYourQuery, yourDBconn))
{
myAdapter.Fill(myDataTable);
}
}
}
答案 1 :(得分:0)
你在这里。测试
FrameLayout