我想检索数据库文件并将每个文件保存为具有相同文件名的文本文件,如数据库。我在数据库中有 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 ! ");
}
}
}
}