如何实现word文件上传到Sql Server数据库,库中字段为text型?急救!!!在线等!
我的代码如下:
//上传文件
if(UP_File.PostedFile!=null)
{
SqlConnection con=new SqlConnection(strConn2);
int textdatalen=UP_File.PostedFile.ContentLength;
string texttype=UP_File.PostedFile.ContentType;
Stream textdatastream=UP_File.PostedFile.InputStream;
// System.IO.FileMode.
byte[] textdata=new byte[textdatalen];
textdatastream.Read(textdata,0,textdatalen);
string strSqlCount="select count(*) as Count from cx_jjsqb where bh='"+maxbh+"'";
int Count=BaseSql.IfExitSql(strSqlCount);
SqlCommand command=new SqlCommand();
command.CommandType=CommandType.Text;
command.Connection=con;
if(Count==0)
command.CommandText="Insert into cx_jjsqb(bh,sqwj) Values(@maxbh,@sqwj)";
else
command.CommandText="Update cx_jjsqb Set sqwj=@sqwj where bh=@maxbh";
SqlParameter parambh=new SqlParameter("@maxbh",SqlDbType.Char,10);
parambh.Value=maxbh;
command.Parameters.Add(parambh);
SqlParameter paramsqwj=new SqlParameter("@sqwj",SqlDbType.Text);
paramsqwj.Value=textdata;
command.Parameters.Add(paramsqwj);
con.Open();
int RowsAffected=command.ExecuteNonQuery();
con.Close();
}
else
Response.Write("<script language='JavaScript'>alert('上传文件不能为空!');</script>");
编译错误如下:
对象必须实现 IConvertible。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidCastException: 对象必须实现 IConvertible。
源错误:
行 193: command.Parameters.Add(paramsqwj);
行 194: con.Open();
行 195: int RowsAffected=command.ExecuteNonQuery();
行 196: con.Close();
行 197: }