FileStream stream=new FileStream("c:\\w.jpg",FileMode.Open,FileAccess.Read);
byte[] blob=new byte[stream.Length];
stream.Read(blob,0,(int)stream.Length);
stream.Close();
string source="server=csl;database=StudentDB;uid=sa;pwd=''";
sqlcon=new SqlConnection(source);
try
{
sqlcon.Open();
string sql="insert into photo(code,photo) values('0001',@photo)";
SqlCommand command=new SqlCommand(sql,sqlcon);
cmd.Parameters.Add("@photo",blob);
//cmd.Parameters.Add("@photo", SqlDbType.Image, blob.Length).Value = blob;
cmd.ExecuteNonQuery();
}
catch(Exception e1)
{
Console.WriteLine("shiba");
}
finally
{
sqlcon.Close();
}
}在插入数据库时,不包任何错误,但数据库中没有数据我的数据库是sqlserver 表结构为photo(code char(4),photo image)
所以:
cmd.Parameters["@photo"].Value = blob;
这么写不正确吗?