我的 Winforms 应用程序有问题。我有一个数据库,用户可以在其中存储文件。不管它是 pdf、png 等...当双击 datagridview 中的一行时,用户应该会看到该文件。我试过这样:
private void DataGridCPU_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
sqlCon.Open();
SqlCommand cmd = sqlCon.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select Dok from cpuTabelle where Id='" + this.DataGridCPU.CurrentRow.Cells[0].Value.ToString() + "'";
var reader = cmd.ExecuteReader();
if (reader.Read())
{
var data = (byte[])reader["Dok"];
var newName = this.DataGridCPU.CurrentRow.Cells[0].Value.ToString()+"_"+ this.DataGridCPU.CurrentRow.Cells[1].Value.ToString();
File.WriteAllBytes(newName, data);
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = newName;
p.Start();
p.WaitForExit();
当我现在双击一行时,会引发标题中的异常。
我还尝试p.StartInfo.ErrorDialog=true;
在该p.Start();
行之前添加,但随后会打开错误框,显示该文件未与执行此操作的应用程序关联,并且出现以下异常:该操作已被用户取消。
我真的不知道该怎么办...
感谢您的帮助。