保存到数据库
public int DyfcListInsert(int id,string name,string username,string content,Byte[] photo)
{
string sql = "S_DyfcList_Insert";
SqlCommand sqlcmd = new SqlCommand(sql,DwzxConfiguration.ConnectDB() ,DwzxConfiguration.SqlTran);
sqlcmd.CommandType = CommandType.StoredProcedure;
if(id>0)
{
sqlcmd.Parameters .Add ("@Id",SqlDbType.Int ,4).Value=id;
}
sqlcmd.Parameters .Add ("@Name",SqlDbType.VarChar ,50).Value=name;
sqlcmd.Parameters .Add ("@UserName",SqlDbType.VarChar ,500).Value=username;
sqlcmd.Parameters .Add ("@Content",SqlDbType.NText ).Value=content;
sqlcmd.Parameters .Add ("@Photo",SqlDbType.Binary).Value=photo;
sqlcmd.Parameters .Add ("@RETURN_VALUE",SqlDbType.Int ,4).Direction=ParameterDirection.ReturnValue ;
sqlcmd.ExecuteNonQuery ();
return (int)sqlcmd.Parameters ["@RETURN_VALUE"].Value ;
}
保存到服务器的方法(
http://www.cnblogs.com/interboy/archive/2007/04/12/710024.aspx)
public byte[] getBytes(string filePath)
{
System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open);
byte[] imgData = new byte[fs.Length];
fs.Read(imgData, 0, (int)fs.Length);
return imgData;
}
byte[] fileData = this.FileUpload1.FileBytes;
string sql = "insert into t_img(img) values (@img)";
string strconn = System.Configuration.ConfigurationManager.ConnectionStrings["fengdongDB"].ToString();
SqlConnection sqlConn = new SqlConnection(strconn);
SqlCommand sqlComm = new SqlCommand(sql, sqlConn);
sqlComm.Parameters.Add("@img", SqlDbType.Image);//添加参数
sqlComm.Parameters["@img"].Value = fileData;//为参数赋值
sqlConn.Open();
sqlComm.ExecuteNonQuery();
sqlConn.Close();
posted @
2007-07-11 12:17
拖拉机大叔
阅读(
295)
评论()
编辑
收藏
举报