//保存老森文件到SQL Server数据库中
FileInfo fi=new FileInfo(fileName);
FileStream fs=fi.OpenRead();
byte[] bytes=new byte[fs.Length];
fs.Read(bytes,0,Convert.ToInt32(fs.Length));
SqlCommand cm=new SqlCommand();
cm.Connection=cn;
cm.CommandType=CommandType.Text;
if(cn.State==0) cn.Open();
cm.CommandText="insert into "+tableName+"("+fieldName+") values(@file)";
SqlParameter spFile=new SqlParameter("@file",SqlDbType.Image);
spFile.Value=bytes;
cm.Parameters.Add(spFile);
cm.ExecuteNonQuery()
//保存文件到Access数侍散亩据库中
FileInfo fi=new FileInfo(fileName);
FileStream fs=fi.OpenRead();
byte[] bytes=new byte[fs.Length];
fs.Read(bytes,0,Convert.ToInt32(fs.Length));
OleDbCommand cm=new OleDbCommand();
cm.Connection=cn;
cm.CommandType=CommandType.Text;
if(cn.State==0) cn.Open();
cm.CommandText="insert into "+tableName+"("+fieldName+") values(@file)";
OleDbParameter spFile=new OleDbParameter("@file",OleDbType.Binary);
spFile.Value=bytes;
cm.Parameters.Add(spFile);
cm.ExecuteNonQuery()
代码中的fileName是文件掘胡的完整名称,tableName是要操作的表名称,fieldName是要保存文件的字段名称
//保存文件到SQL Server数据库中
FileInfo fi=new FileInfo(fileName);
FileStream fs=fi.OpenRead();
byte[] bytes=new byte[fs.Length];
fs.Read(bytes,0,Convert.ToInt32(fs.Length));
SqlCommand cm=new SqlCommand();
cm.Connection=cn;
cm.CommandType=CommandType.Text;
if(cn.State==0) cn.Open();
cm.CommandText="insert into "+tableName+"("+fieldName+") values(@file)";
SqlParameter spFile=new SqlParameter("@file",SqlDbType.Image);
spFile.Value=bytes;
cm.Parameters.Add(spFile);
cm.ExecuteNonQuery()
//保存文件到Access数据库中
FileInfo fi=new FileInfo(fileName);
FileStream fs=fi.OpenRead();
byte[] bytes=new byte[fs.Length];
fs.Read(bytes,0,Convert.ToInt32(fs.Length));
OleDbCommand cm=new OleDbCommand();
cm.Connection=cn;
cm.CommandType=CommandType.Text;
if(cn.State==0) cn.Open();
cm.CommandText="insert into "+tableName+"("+fieldName+") values(@file)"老森;
OleDbParameter spFile=new OleDbParameter("@file",OleDbType.Binary);
spFile.Value=bytes;
cm.Parameters.Add(spFile);
cm.ExecuteNonQuery()
代码中的掘胡fileName是文件的完整名侍散亩称,tableName是要操作的表名称,fieldName是要保存文件的字段名称