user5067119
user5067119

Reputation: 155

ASP.NET : Error - Column name or number of supplied values does not match table definition

i'm working with ASP.NET web application project . in my Registration page i asked the user to upload a photo but when i try to upload this error shows up in the browser at line Line 83:

Line 81:                 comm.Parameters.AddWithValue("@License", License);
Line 82:                 conn.Open();
Line 83:                 int row = comm.ExecuteNonQuery();
Line 84:                 conn.Close();
Line 85:                 if (row > 0) { LabelError.Text = "DONE"; }

my DB table :

CREATE TABLE [dbo].[DeliveryMen] (
    [Delivery_ID] INT             IDENTITY (1, 1) NOT NULL,
    [Name]        NVARCHAR (50)   NOT NULL,
    [Username]    NVARCHAR (50)   NOT NULL,
    [Password]    NVARCHAR (50)   NOT NULL,
    [Email]       NVARCHAR (50)   NOT NULL,
    [Phone]       NVARCHAR (50)   NOT NULL,
    [City]        NVARCHAR (50)   NOT NULL,
    [License]     VARBINARY(MAX) NOT NULL,
    [Latitude]    NUMERIC (18)    NOT NULL,
    [Longitude]   NUMERIC (18)    NOT NULL,
    PRIMARY KEY CLUSTERED ([Delivery_ID] ASC)
);

in case you need the insert function :

 public void insert()
        {

            if (FileUpload1.PostedFile.FileName != "")
            {
                byte[] License;
                Stream s = FileUpload1.PostedFile.InputStream;
                BinaryReader br = new BinaryReader(s);
                License = br.ReadBytes((Int32)s.Length);
                 SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString);
                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = "insert into DeliveryMen values(@License) SELECT '7'";
                comm.Parameters.AddWithValue("@License", License);
                conn.Open();
                int row = comm.ExecuteNonQuery();
                conn.Close();
                if (row > 0) { LabelError.Text = "DONE"; }
            }
            else LabelError.Text = "Please upload the photo";
        }

Upvotes: 0

Views: 592

Answers (1)

Niels Filter
Niels Filter

Reputation: 4528

As Soner Gönül mentioned in the comments, change your SQL to list the column name(s) and the parameter value(s)

comm.CommandText = "insert into DeliveryMen (License) values (@License);";

Upvotes: 2

Related Questions