C# ASP.NET:错误-提供的值的列名或数目与表定义不匹配
我正在从事ASP.NET web应用程序项目。在我的注册页面中,我要求用户上载照片,但当我尝试上载时,浏览器第83行显示此错误:C# ASP.NET:错误-提供的值的列名或数目与表定义不匹配,c#,sql,asp.net,upload,C#,Sql,Asp.net,Upload,我正在从事ASP.NET web应用程序项目。在我的注册页面中,我要求用户上载照片,但当我尝试上载时,浏览器第83行显示此错误: Line 81: comm.Parameters.AddWithValue("@License", License); Line 82: conn.Open(); Line 83: int row = comm.ExecuteNonQuery(); Line 84:
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"; }
我的数据库表:
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)
);
如果您需要插入功能:
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";
}
正如注释中提到的Soner Gönül一样,将您的
SQL
更改为列出列名和参数值
您是否曾经尝试将您的列指定为插入DeliveryMen(许可证).
,因为您的表有多个列?也许它尝试在没有任何列规范的情况下将其插入到第一列?顺便问一下,选择“7”是为了什么?@SonerGönül我在这里做了插入DeliveryMen值(@License)选择“7”
,这是我知道的唯一方法。。我应该在哪里指定送货员(许可证)
?
comm.CommandText = "insert into DeliveryMen (License) values (@License);";