Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 插入图像,然后插入数据库的文件路径_Asp.net - Fatal编程技术网

Asp.net 插入图像,然后插入数据库的文件路径

Asp.net 插入图像,然后插入数据库的文件路径,asp.net,Asp.net,我正在我的网页中设计: namespace photoshops { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e)

我正在我的网页中设计:

namespace photoshops
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
             onflbload(sender, e);
        }
        public void onflbload(object sender, EventArgs e)
        {
            // Create a byte[] from the input file

            int len = flbload.PostedFile.ContentLength;
            byte[] pic = new byte[len];
            flbload.PostedFile.InputStream.Read(pic, 0, len);
            // Insert the image and comment into the database

            SqlConnection connection = new SqlConnection(@"Data Source=DEVI\SQLEXPRESS; 
                          Initial Catalog =cat; Integrated Security=SSPI");

            try
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand("insert into tblphotosettings " +
                    "(BillNo,CustomerName,Address,StartDate,EndDate,Systemurl,Numberofcopies,Amount,Total)  
                    values (@BillNo,@CustomerName,@Address,@StartDate,@EndDate,@Systemurl,@Numberofcopies,@Amount,@Total)", connection);
                cmd.Parameters.Add("@BillNo", SqlDbType.NVarChar).Value = TextBox1.Text;
                cmd.Parameters.Add("@CustomerName", SqlDbType.NVarChar).Value =TextBox2.Text;
                cmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value = TextBox3.Text;
                cmd.Parameters.Add("@StartDate", SqlDbType.NVarChar).Value = Rdbsdate.SelectedDate;
                cmd.Parameters.Add("@EndDate", SqlDbType.NVarChar).Value = Rdbddate.SelectedDate;
                cmd.Parameters.Add("@Systemurl", SqlDbType.Image).Value = pic;
                SqlParameter Src = new SqlParameter("@FilePath", SqlDbType.VarChar, 450);
                Src.Value = pic.GetName();
                cmd.Parameters.Add(Src);

                cmd.Parameters.Add("@Numberofcopies", SqlDbType.NVarChar).Value =TextBox7.Text;
                cmd.Parameters.Add("@Amount", SqlDbType.NVarChar).Value = TextBox8.Text;
                cmd.Parameters.Add("@Total", SqlDbType.NVarChar).Value = TextBox9.Text;
                cmd.ExecuteNonQuery();
            }

            finally
            {
                connection.Close();
            }
        }
    }
 }
我的错误

Error   1   'System.Array' does not contain a definition for 'GetName'   
and no extension method 'GetName' accepting a first argument of type 'System.Array' could 
be found (are you missing a using directive or an assembly reference?)  
C:\Documents and Settings\Administrator\My Documents\Visual Studio 
2008\Projects\photoshops\photoshops\photosetting.aspx.cs    52  29  photoshops

听起来您希望图像在数据库中的位置

string flPath = "C:\\1\\noimg.png";
byte[] imageBytes =  File.ReadAllBytes(flPath);
您的代码实际上有
字节[]
INSERT
语句中使用:

 cmd.Parameters.Add("@Systemurl", SqlDbType.Image).Value = pic;
建议挑一个:

  • 继续将二进制文件保存到数据库,如上所述
  • 字节[]
    作为文件保存到磁盘上的某个位置。使用该文件名,如下所示:

听起来您希望图像在数据库中的位置

string flPath = "C:\\1\\noimg.png";
byte[] imageBytes =  File.ReadAllBytes(flPath);
您的代码实际上有
字节[]
INSERT
语句中使用:

 cmd.Parameters.Add("@Systemurl", SqlDbType.Image).Value = pic;
建议挑一个:

  • 继续将二进制文件保存到数据库,如上所述
  • 字节[]
    作为文件保存到磁盘上的某个位置。使用该文件名,如下所示:

您只需要执行代码2行,就可以从文件路径存储图像,并将其存储到数据库中

string flPath = "C:\\1\\noimg.png";
byte[] imageBytes =  File.ReadAllBytes(flPath);

imageBytes
是您感兴趣的部分,它包含图像的整个字节数组,您只需将其插入到图像数据类型表的列中。

您只需执行代码2行,就可以从文件路径存储图像并将其存储到数据库中

string flPath = "C:\\1\\noimg.png";
byte[] imageBytes =  File.ReadAllBytes(flPath);


imageBytes
是您感兴趣的部分,它包含图像的整个字节数组,您只需将其插入到图像数据类型表的列中。

非主题注释:System.Windows.Forms.MessageBox.Show-在中不起作用ASPX@vs戴夫:这不完全正确,它将工作,但它将显示在服务器上side@Pawe斯梅伊达:你试过吗?它是如何工作的?MessageBox停止代码执行,等待用户输入;如果它显示在服务器端,用户将如何知道?@vs dev是的,我尝试过vs开发server@TomGullen映像位置未存储在数据库sqlsever2005An中主题注释:System.Windows.Forms.MessageBox.Show-在中不起作用ASPX@vs戴夫:这不完全正确,它将工作,但它将显示在服务器上side@Pawe斯梅伊达:你试过吗?它是如何工作的?MessageBox停止代码执行,等待用户输入;如果它显示在服务器端,用户将如何知道?@vs dev是的,我尝试过vs开发server@TomGullen图像位置未存储在数据库中sqlsever2005@p.campbell我使用,但错误无法将参数值从字节[]转换为字符串。@Sachin Shanbhag错误无法将参数值从字节[]转换为字符串@vimal:您需要实现一些代码来实际将映像保存到磁盘,确定磁盘上的文件名,并将其用作
myImagePathOnDisk
。我的回答只是试图引导您找到一个整体解决方案。@curt Error无法将参数值从字节[]转换为字符串。@LERTWAT W。Error无法将参数值从字节[]转换为字符串String@p.campbell我使用,但错误是无法从字节[]转换参数值转换为字符串。@Sachin Shanbhag错误无法将参数值从字节[]转换为字符串。@vimal:您需要实现一些代码来实际将映像保存到磁盘,确定磁盘上的文件名,并将其用作
myImagePathOnDisk
。我的回答只是试图引导您找到一个整体解决方案。@curt Error无法将参数值从字节[]转换为字符串。@LERTWAT W。Error无法将参数值从字节[]转换为字符串