提示:从索引0处开始,初始化字符串的格式不符合规范。
大家帮小妹我看看程序吧,实在查不出什么问题了,设置断点也不行。小妹我分数不多,除了给分之外,我只能说谢谢。先谢谢大家了。
下面是程序里面的部分代码,目的是数据备份
private void btnDStore_Click(object sender, EventArgs e)
{
SQL s = new SQL();//连接数据库,使用的是一个编好的类
System.Data.DataTable dTable = new System.Data.DataTable();//构造数据表
try
{
if (File.Exists(txtDSPath.Text.Trim() + ".bak"))
{
MessageBox.Show("该文件已经存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtDSPath.Text = "";
txtDSPath.Focus();
}
else
{
//以下几行是按照SQL类编的手动备份程序
string fileName = DateTime.Now.ToString("yyyy-MM-dd-s");
if (s.BackupDataBase(fileName))
{
MessageBox.Show("数据备份成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
我在fileName那里设置断点,显示的就是日期,比如说2011-11-21-21这样的,我用的是时间作为备份文件的名称。
下面是编写的SQL类里面的一部分代码。
public bool BackupDataBase(string fileName)
{
string cmd = "USE master BACKUP DATABASE myDB TO DISK='D:\\myDataBase\\" + fileName + ".bak' WITH INIT";
SqlConnection conn = new SqlConnection(ConnectionString);
SqlCommand command = new SqlCommand(cmd, conn);
try
{
conn.Open();
command.ExecuteNonQuery();
conn.Close();
return true;
}
catch (SqlException ex)
{
_Message = ex.Message;
conn.Close();
return false;
}
}