我想要检索数据库文件并将每个文件保存为具有相同文件名的文本文件,例如database。我在数据库中有500个文件,我想在我的本地机器中保存所有文件。
我在下面试过但是没有用。任何人都可以修改或编辑以下代码..
private void button1_Click(object sender, System.EventArgs e)
{
string connetionString = null;
SqlConnection connection;
SqlCommand command;
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds = new DataSet();
int i = 0;
string sql = null;
connetionString = "Data Source=edevsql2k5-01;Initial Catalog=AIFSOnBase;Integrated Security=True";
sql = "SELECT vbscript FROM hsi.vbscripttable WHERE vbscriptnum=101";
connection = new SqlConnection(connetionString);
Directory.CreateDirectory("c:\\VBScriptFiles");
try
{
connection.Open();
command = new SqlCommand(sql, connection);
adapter.SelectCommand = command;
adapter.Fill(ds);
adapter.Dispose();
command.Dispose();
connection.Close();
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
MessageBox.Show(ds.Tables[0].Rows[i].ItemArray[0].ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection ! ");
}
}
}
}