我正在使用ASP.NET Web应用程序项目。在我的注册页面中,我要求用户上传照片,但当我尝试上传时,此错误显示在第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"; }
我的数据库表:
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";
}
答案 0 :(得分:2)
正如SonerGönül在评论中提到的那样,将SQL
更改为列出column name(s)
和parameter value(s)
comm.CommandText = "insert into DeliveryMen (License) values (@License);";