2016-11-15 7 views
0

ASP.NET WebフォームWebサイトの「Images」フォルダに画像を保存しようとしています。 IDENTITYインクリメント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を更新する必要があります。ここでは

は私のsubmitボタンの背後にあるコードでありますIdentity Increment

関連する問題