//读取
private void Get_data_Click(object sender, EventArgs e)
{
OpenFileDialog GetData = new OpenFileDialog(); //以打开的方式
GetData.Multiselect = false; //该值确定是否可以选择多个文件
GetData.Title = "请选择文件"; //标题
GetData.InitialDirectory = @"C:\"; //默认打开C:\路径(可更改)
GetData.Filter = "SQL文件(*.sql)|*.sql"; //限制只显示文件夹及后缀为sql的文件(可根据需求更改)
string script = " ";
if (GetData.ShowDialog() == DialogResult.OK) //如果选择了文件
{
script = GetData.FileName; //script赋值为所选文件的路径
}
}
//保存
private void Save_Data_Click(object sender, EventArgs e)
{
SaveFileDialog SaveData = new SaveFileDialog(); //以保存文件的方式打开
SaveData.Title = "请选择路径"; //标题
SaveData.InitialDirectory = @"C:\"; //默认路径是C:\,可更改
SaveData.Filter = "SQL文件(*.sql)|*.sql"; //只能保存为sql文件(可根据需求更改)
string script = " ";
SaveData.FileName = "script"; //默认文件名是script(.sql是自动补的)
if (SaveData.ShowDialog() == DialogResult.OK) //如果选定路径按下保存按钮
{
script = SaveData.FileName; //script赋值为选择保存的路径
}
}