开发者

Asp.net how to correct the error [duplicate]

This question already has an answer here: Closed 11 years ago.

Possible Duplicate:

Asp.net how to correct the error

I'm designing my web page

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using S开发者_开发百科ystem.Data.sqldbType.Nvarchar;

    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 tblphotosetting "
             + "

(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;
            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();
        }
    }
}
}

My error is image are not insert


I think you want SqlDbType instead of sqldbtype

More info here

using System.Data.sqldbType.Nvarchar;

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;
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();

It appears as though you are trying to save a byte[] to your table 'tblphotosetting' but the corresponding field in the table (Systemurl) is expecting an item of data of type varchar. You need to decide what you actually want to save in that field and either adjust the table schema, or the database code.

So the desire is in fact to store an image in the systemUrl field of the table 'tblphotosetting'. This field is currently a varchar so will need to be of type 'Image'. The following SQL script will make this change.

alter table tblphotosetting 
    alter column Systemurl image null

Also there has been a bit of a theme in this question answer session whereby casing has not been used correctly in this C# code, therefore I would suggest that if an IDE is not already being used, then one can download and use Visual Studio Express for free.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜