2016-11-15 75 views
0

我試圖將圖像存儲在我的ASP.NET Web表單網站的'Images'文件夾中。System.Data.SqlClient.SqlException'發生了

這背後是我的提交按鈕的代碼:

protected void btnSubmit_Click(object sender, EventArgs e) 
{ 
    //Get Filename from fileupload control 
    string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName); 
    //Save images into Images folder 
    fileuploadimages.SaveAs(Server.MapPath("Images/" + filename)); 
    //Getting dbconnection from web.config connectionstring 
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["BallinoraDBConnectionString1"].ToString()); 
    //Open the database connection 
    con.Open(); 
    //Query to insert images path and name into database 
    SqlCommand cmd = new SqlCommand("Insert into Group_Images(ImageName,ImagePath) values(@ImageName,@ImagePath)", con); 
    //Passing parameters to query 
    cmd.Parameters.AddWithValue("@ImageName", filename); 
    cmd.Parameters.AddWithValue("@ImagePath", "Images/" + filename); 
    cmd.ExecuteNonQuery(); 
    //Close dbconnection 
    con.Close(); 
    Response.Redirect("~/Admin.aspx"); 
} 

SQL Server table structure

Here is the error message I'm receiving

+0

表結構沒有進入崗位。你可以添加它嗎?謝謝:) – scsimon

+1

嘗試閱讀錯誤消息。 – SLaks

+0

@scsimon忘記了添加鏈接!謝謝。 – user2911539

回答

1

你在你的數據庫中更新列ID,將其設置爲標識增量

Identity Increment

相關問題