我想用这个C#代码进行数据库备份:
connect = new SqlConnection(con);
connect.Open();
// Execute SQL
SqlCommand command = new SqlCommand
(
@"backup database MY_database to disk='d:\SQLBackup\wcBackUp1.bak' with init, stats=10",
connect
);
command.ExecuteNonQuery();
connect.Close();
Run Code Online (Sandbox Code Playgroud)
当我运行它时,会出现以下错误消息:
无法打开备份设备'd:\ SQLBackup\wcBackUp1.bak'.操作系统错误3(系统找不到指定的路径.).
如果我改变d:\wcBackUp1.bak它的路径似乎没问题,没有错误,但文件不存在,它没有生成.
如果我在SQL中运行命令,我会收到100%处理的消息,但是我没有看到该文件.
有人可以帮帮我吗?
我有两种形式:Form1和Form2.
我想在加载Form1时将Form2显示为对话框.我的意思是当Form1加载并对用户可见时,Form2显示为对话框.
在Form1_Load事件中,它首先将Form2显示为对话框,然后显示Form1.
如何首先将Form1和Form2显示为对话框?
我正在使用C#编写Windows窗体应用程序。
我发现有人对如何List<>从DataGridView控件创建对象的建议,但在如何提取单元格值方面我需要更多的帮助。
这是给出的代码;假设dataGridView1are Name和中的两列Address。
如何建立List<ProjList>物件?
foreach (DataGridViewRow dr in dataGridView1.Rows)
{
ProjList = new List<ProjectMasterRec>();
foreach (DataGridViewCell dc in dr.Cells)
{
// build out MyItem
// based on DataGridViewCell.OwningColumn and DataGridViewCell.Value
// how do we code this?
}
ProjList.Add(item);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个 LINQ 表达式,以从 int 属性中过滤值:
protected IQueryable<T> Some(IEnumerable<int> ids)
{
var parameter = Expression.Parameter(typeof(T), "x");
// "Col_id" (int property)
var property = Expression.Property(parameter, "Col_id");
MethodInfo method = typeof(Enumerable).
GetMethods().
Where(x => x.Name == "Contains").
Single(x => x.GetParameters().Length == 2).
MakeGenericMethod(typeof(T));
// ids = { 2, 4, 8 } etc...
var value = Expression.Constant(ids, typeof(IEnumerable<int>));
var containsMethod = Expression.Call(method, property, value); // exception
var aDelegate = Expression.Lambda<Func<T, bool>>(containsMethod, parameter);
table = myDataContext.GetTable<T>();
return table.AsQueryable().Where(aDelegate);
}
Run Code Online (Sandbox Code Playgroud)
我试图得到类似的东西:(x => ids.Contains(x.Col_id)),但抛出异常:
'System.Int32' …
c# ×4
winforms ×3
backup ×1
contains ×1
datagridview ×1
ienumerable ×1
linq ×1
list ×1
modal-dialog ×1
sql ×1
sql-server ×1