写了个图片导入到数据库的函数,建了个测试的数据库,导入正常,但是在令外一个数据库上就不起作用,烦恼,可能不是代码的原因,但是实在是找不到原因 代码发出来大家帮忙看下 public static void Import(string path) //遍历文件夹(包括子文件夹)内的图片,并将图片导入到数据库中
{
DirectoryInfo di=new DirectoryInfo(path);
FileInfo[] files = di.GetFiles(); string strConn = "data source=localhost;uid=kem;pwd=xzkem;database=HealthCare";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
foreach (FileInfo file in files)
{
string name = file.Name;
string fullpath =path +@"\"+name;
string rybh = Path.GetFileNameWithoutExtension(fullpath);
byte[] photo = GetPhoto(fullpath); string sql = "update Operator set m_Photo=@pic where Rybh="+rybh;
//MessageBox.Show("数据库连接成功1");
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@pic", SqlDbType.Image, photo.Length).Value = photo;
cmd.ExecuteNonQuery();
}
conn.Close();
MessageBox.Show("导入成功");
}
{
DirectoryInfo di=new DirectoryInfo(path);
FileInfo[] files = di.GetFiles(); string strConn = "data source=localhost;uid=kem;pwd=xzkem;database=HealthCare";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
foreach (FileInfo file in files)
{
string name = file.Name;
string fullpath =path +@"\"+name;
string rybh = Path.GetFileNameWithoutExtension(fullpath);
byte[] photo = GetPhoto(fullpath); string sql = "update Operator set m_Photo=@pic where Rybh="+rybh;
//MessageBox.Show("数据库连接成功1");
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@pic", SqlDbType.Image, photo.Length).Value = photo;
cmd.ExecuteNonQuery();
}
conn.Close();
MessageBox.Show("导入成功");
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货