当前位置:编程学习 > C#/ASP.NET >>

紧急,求助

MyConn = DB.CreateDB();

                string title =FunStr(this.TxtTitle.Text);
                string content =FunStr(this.TxtContent.Text);
                string ptype = Request.QueryString["action"].ToString();
                string FileName = myFile.Value;
                HttpPostedFile UpFile = myFile.PostedFile; //获取对由客户端指定的上传文件的访问
                FileLength = UpFile.ContentLength;//获取上传文件的字节大小
                if (FileLength == 0)
                {
                    MyConn.Open();
                    OleDbCommand cmd1 = new OleDbCommand("insert into product(pro_name,title,content) values('" + ptype + "','" + title + "','" + content + "')",MyConn);
                    cmd1.ExecuteNonQuery();
                    Response.Write("<script>alert('数据添加成功');window.location.href='Admin_Add.aspx?action=" + ptype + "'</script>");
                    MyConn.Close();
                }
                else
                {
                    string exName = FileName.Substring(FileName.LastIndexOf(".") + 1).ToUpper();//截取图片的后缀名
                    if (exName == "JPG" || exName == "BMP" || exName == "GIF")//判断图片的类型
                    {
                        if (FileLength > 204800)//判断图片是否大于200k(根据自己的需要判断大小)
                        {
                            Response.Write("<script>alert('对不起,图片大小不能大于200K');window.location.href='Admin_Add.aspx?action=" + ptype + "'</script>");
                            return;
                        }
                        else
                        {
                            string ImageName = DateTime.Now.ToString("yyyyMMddhhmmssfff") + "." + exName;//图片名称设置为保存的时间
                            Byte[] FileByte = new Byte[FileLength]; //图象文件储存到数组  
                            Stream ObjectStream = UpFile.InputStream;//建立数据流对像,获取一个 Stream 对象,该对象指向一个上载文件,以准备读取该文件的内容。

                            ObjectStream.Read(FileByte, 0, FileLength); //读取图象文件数据
                            string StrSql = "Insert Into product(pro_name,img,title,content) Values('" + ptype + "',@ImageName,'" + title + "','" + content + "')";
                            OleDbCommand Cmd = new OleDbCommand(StrSql, MyConn);
                            //Cmd.Parameters.Add("@Image",OleDbType.Binary, FileLength).Value = FileByte;
                            Cmd.Parameters.Add("@ImageName", OleDbType.VarChar, 100).Value = ImageName;
                            MyConn.Open();
                            this.myFile.PostedFile.SaveAs(Server.MapPath("/upload") + "\\img" + ImageName);
                            Cmd.ExecuteNonQuery();
                            MyConn.Close();
                            Response.Write("<script>alert('数据添加成功');window.location.href='Admin_Add.aspx?action="+ptype+"'</script>");
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('对不起,请选择正确的的图片!');window.location.href='Admin_Add.aspx?action=" + ptype + "'</script>");
                        return;
                    }
                }
                

            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message + "')</script>");
            }
        }

    }

最后 提示  未将对象引用设置到对象的实例。。。

高手帮我一下,虽然现在分少,以后我一定会加的。。。 --------------------编程问答--------------------
引用楼主 qq4750523 的回复:
最后 提示 未将对象引用设置到对象的实例。。。


错误定位到了哪句?是string ptype = Request.QueryString["action"].ToString();这句? --------------------编程问答-------------------- 在上传时要先判断一下是否真的上传了文件,如果没有就不要做任何处理,有才往数据库写。 --------------------编程问答-------------------- 2L你QQ是多少?
能私下和你说吗? --------------------编程问答--------------------
引用 2 楼 zhoufoxcn 的回复:
在上传时要先判断一下是否真的上传了文件,如果没有就不要做任何处理,有才往数据库写。



2L你QQ是多少?
能私下和你说吗
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,