我想通过点击datagridview控件中的datagridviewlinkcolumn,来实现打开数据库中的文件
但是我这一段始终不能实现
最后提示错误为invalidOperationException尚未提供文件名,所以无法启动谁能救救我啊···private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{ SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Server=PC-201106241704;Integrated Security=True;" + "DataBase=chengdu";
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn; cmd.CommandText = "Select 文件, 文件 from XSdcTable";
FileStream fs;
BinaryWriter bw;
int buffersize = 100;
byte[] outbyte = new byte[buffersize];
long reval;
long startIndex;
string filePath = @"C:/wordData.doc";
conn.Open();
SqlDataReader reader;
reader = cmd.ExecuteReader();
while (reader.Read())
{
fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(fs);
startIndex = 0;
reval = reader.GetBytes(0, startIndex, outbyte, 0, buffersize);
while (reval == buffersize)
{
bw.Write(outbyte);
bw.Flush();
startIndex += buffersize;
reval = reader.GetBytes(0, startIndex, outbyte, 0, buffersize);
}
bw.Write(outbyte, 0, (int)reval );
bw.Flush();
bw.Close();
fs.Close();
}
reader.Close();
conn.Close();
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
if (e.ColumnIndex != 0)
{
System.Diagnostics.Process.Start(dataGridView2.Rows[i].Cells[0].Value.ToString());
}
}
}
但是我这一段始终不能实现
最后提示错误为invalidOperationException尚未提供文件名,所以无法启动谁能救救我啊···private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{ SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Server=PC-201106241704;Integrated Security=True;" + "DataBase=chengdu";
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn; cmd.CommandText = "Select 文件, 文件 from XSdcTable";
FileStream fs;
BinaryWriter bw;
int buffersize = 100;
byte[] outbyte = new byte[buffersize];
long reval;
long startIndex;
string filePath = @"C:/wordData.doc";
conn.Open();
SqlDataReader reader;
reader = cmd.ExecuteReader();
while (reader.Read())
{
fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(fs);
startIndex = 0;
reval = reader.GetBytes(0, startIndex, outbyte, 0, buffersize);
while (reval == buffersize)
{
bw.Write(outbyte);
bw.Flush();
startIndex += buffersize;
reval = reader.GetBytes(0, startIndex, outbyte, 0, buffersize);
}
bw.Write(outbyte, 0, (int)reval );
bw.Flush();
bw.Close();
fs.Close();
}
reader.Close();
conn.Close();
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
if (e.ColumnIndex != 0)
{
System.Diagnostics.Process.Start(dataGridView2.Rows[i].Cells[0].Value.ToString());
}
}
}
建议逐语句debug,找出错误的语句
System.Diagnostics.Process.Start(dataGridView2.Rows[i].Cells[0].Value.ToString());
出的错,LZ你后面那些格子里都有值吗?是绝对路径吗?为嘛要启动这么多进程