file1 為<input type=file id=file1 name=file1.....中的id.
解决方案 »
- asp.net 怎么接收PHP发过来的XML POST方法
- Repeater 列数
- [散分]马上就要年底了,祝大家节日快乐!!!
- 高分在线等:access绑定datalist的莫名问题
- 一个存储过程的小问题
- CheckBoxList1.Items 索引超出范围
- 高分求教WebService传参数问题!!
- 为什么我的页面基类(父类)的page_load事件发生在子类page_load后面啊?
- vs2005网站根目录下有个xml配置文件和Web.config文件,那么他们之间有何区别?
- 如何重从数据库中获取dropdownbutoon里面listitem的数据呢
- 新手的两段简单代码 一个是书上的;一个是别人给的,有什么区别谢谢,第二个运行不了
- 请问这条赋值语句怎么写(C#)
filel可以设置为runat=server
runat=server
加上试试!
{
//取得上传文件的长度
lenstr = File1.PostedFile.ContentLength; //HttpPostedFile对象,用于读取图象文件属性 if(File1.PostedFile == null && File1.PostedFile.ContentLength ==0)
{
Response.Write("<script language=javascript>alert('文档大小0K!')</script>");
//Response.End();
}
else
{
if (lenstr > 102400)
{
Response.Write("<script language=javascript>alert('文档大小不能超过100K!')</script>");
}
else
{
//Response.Write(lenstr); Sql = "insert into kj_MainPictureLink values("+DropDownList1.SelectedItem.Value.ToString()+",@Img_FileName,@Img_Type,@Img_Size,@Tab_Image,'"+TextBox1.Text.ToString()+"','"+DateTime.Now+"')"; SqlConnection MyConnection = new SqlConnection(Application["MySource"].ToString()); SqlCommand MyCommand = new SqlCommand(Sql,MyConnection); //MyCommand.Parameters.Add("@Tab_Image",SqlDbType.Image, lenstr).Value=imagebytes; //文件名
SqlParameter param = new SqlParameter("@Img_FileName",SqlDbType.NVarChar,100);
param.Value = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\")+1);
MyCommand.Parameters.Add(param); //文件类型
param = new SqlParameter("@Img_Type",SqlDbType.NVarChar,50);
param.Value = File1.PostedFile.ContentType;
MyCommand.Parameters.Add(param); //文件大小
param = new SqlParameter("@Img_Size",SqlDbType.Float,8);
param.Value = lenstr;
MyCommand.Parameters.Add(param); //文件内容
byte[] context = new Byte[lenstr];
param = new SqlParameter("@Tab_Image",SqlDbType.Image);
File1.PostedFile.InputStream.Read(context,0,lenstr);
param.Value = context;
MyCommand.Parameters.Add(param); MyConnection.Open();
//进行输入
try
{
MyCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.Message);
} info.Text = "录入成功!"; TextBox1.Text = ""; Response.Write("<script language=javascript>alert('录入成功!');</script>");
}
}
}