ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Multiple records are getting inserted at once using asp.net c#<p>Hey <a class="username" rel="democloud"> democloud</a>,</p> <p>Please take reference to the below code and correct you code.</p> <p>Remove second table code and put it outside of loop and first table code put in loop.</p> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <pre class="brush: csharp">protected void Insert(object sender, EventArgs e) { if (FileUpload1.HasFile) { string staffname = DropDownList1.SelectedItem.Text; string constr = ConfigurationManager.ConnectionStrings[&#34;crm_db&#34;].ConnectionString; SqlConnection con = new SqlConnection(constr); //code for second table SqlCommand cmd1 = new SqlCommand(&#34;crm_sp_insert_staffcompliance&#34;, con); cmd1.CommandType = CommandType.StoredProcedure; cmd1.Connection = con; cmd1.Parameters.AddWithValue(&#34;@email&#34;, txt_email.Text); cmd1.Parameters.AddWithValue(&#34;@Birth_Certificate&#34;, str1); cmd1.Parameters.AddWithValue(&#34;@Degree_Certificate&#34;, str2); cmd1.Parameters.AddWithValue(&#34;@Address_Proof&#34;, str3); cmd1.Parameters.AddWithValue(&#34;@Resume&#34;, str4); cmd1.Parameters.AddWithValue(&#34;@Driving_Licence&#34;, str5); if (licencedate.Text == &#34;&#34;) { cmd1.Parameters.AddWithValue(&#34;@driving_date&#34;, DateTime.MinValue.ToLongDateString()); } else { cmd1.Parameters.AddWithValue(&#34;@driving_date&#34;, Convert.ToDateTime(licencedate.Text)); } cmd1.Parameters.AddWithValue(&#34;@Visa_document&#34;, str6); if (txt_date.Text == &#34;&#34;) { cmd1.Parameters.AddWithValue(&#34;@visa_date&#34;, DateTime.MinValue.ToLongDateString()); } else { cmd1.Parameters.AddWithValue(&#34;@visa_date&#34;, Convert.ToDateTime(txt_date.Text)); } cmd1.Parameters.AddWithValue(&#34;@Police_check&#34;, str7); if (txt_policechk.Text == &#34;&#34;) { cmd1.Parameters.AddWithValue(&#34;@police_date&#34;, DateTime.MinValue.ToLongDateString()); } else { cmd1.Parameters.AddWithValue(&#34;@police_date&#34;, Convert.ToDateTime(txt_policechk.Text)); } cmd1.Parameters.AddWithValue(&#34;@ID_check&#34;, str8); cmd1.Parameters.AddWithValue(&#34;@staffname&#34;, DropDownList1.SelectedItem.Text); cmd1.Parameters.AddWithValue(&#34;@created_on&#34;, indianTime); cmd1.Parameters.AddWithValue(&#34;@created_by&#34;, uname); con.Open(); cmd1.ExecuteNonQuery(); con.Close(); foreach (HttpPostedFile postedFile in FileUpload1.PostedFiles) { string filename = Path.GetFileName(postedFile.FileName); string contentType = postedFile.ContentType; Stream fs = postedFile.InputStream; BinaryReader br = new BinaryReader(fs); byte[] bytes = br.ReadBytes((Int32)fs.Length); //code for first table SqlCommand cmd = new SqlCommand(&#34;INSERT INTO tblfiles(Name,ContentType,Data,staffname) VALUES(@Name,@ContentType,@Data,@staffname)&#34;, con); cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = con; cmd.Parameters.AddWithValue(&#34;@Name&#34;, filename); cmd.Parameters.AddWithValue(&#34;@ContentType&#34;, contentType); cmd.Parameters.AddWithValue(&#34;@Data&#34;, bytes); cmd.Parameters.AddWithValue(&#34;@staffname&#34;, staffname); cmd.Parameters.AddWithValue(&#34;@created_on&#34;, indianTime); cmd.Parameters.AddWithValue(&#34;@created_by&#34;, uname); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } ScriptManager.RegisterStartupScript(this, this.GetType(), &#34;SweetAlert&#34;, &#34;swal(&#39;Success!&#39;, &#39;Staff Documents Uploaded successfully.!&#39;, &#39;success&#39;);&#34;, true); } }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/667622/Multiple-records-are-getting-inserted-at-once-using-aspnet-c/https://www.aspforums.net:443/Threads/667622/Multiple-records-are-getting-inserted-at-once-using-aspnet-c/Wed, 14 Nov 2018 02:46:31 GMT