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.Insert Data into Parent and Child Tables from GridView using C# in ASP.Net<p>Hi <a class="username" rel="akhter"> akhter</a>,</p> <p>Refer below code.</p> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <pre class="brush: csharp">using System.Data.SqlClient; using System.Data; </pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <pre class="brush: csharp">public object PID { get; set; } protected void Save_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); if (txtRefno.Text == &#34;&#34;) { Response.Write(&#34;&lt;script language=&#39;javascript&#39;&gt;alert(&#39;Please Input Orderno Ref.&#39;);&lt;/script&gt;&#34;); } else { SqlCommand cmd = new SqlCommand(&#34;[Sp_BalPakinsert]&#34;, con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue(&#34;@Order_Ref_No&#34;, txtRefno.Text); cmd.Parameters.AddWithValue(&#34;@OrderNo&#34;, txtOrder.Text); con.Open(); PID = Convert.ToInt32(cmd.ExecuteScalar()); DataTable dt = (DataTable)ViewState[&#34;dt&#34;]; int pid, codeitem, qty, orderno, prdno; foreach (DataRow row in dt.Rows) { cmd = new SqlCommand(&#34;[SP_BalPakDetail_Insert]&#34;, con); cmd.CommandType = CommandType.StoredProcedure; pid = int.Parse(row[&#34;_PID&#34;].ToString()); prdno = int.Parse(row[&#34;Prdno&#34;].ToString()); orderno = int.Parse(row[&#34;Orderno&#34;].ToString()); qty = int.Parse(row[&#34;QTY&#34;].ToString()); codeitem = int.Parse(row[&#34;Codeitem&#34;].ToString()); cmd.Parameters.AddWithValue(&#34;@pid&#34;, pid); cmd.Parameters.AddWithValue(&#34;@CodeItem&#34;, codeitem); cmd.Parameters.AddWithValue(&#34;@QTY&#34;, qty); cmd.Parameters.AddWithValue(&#34;@Orderno&#34;, orderno); cmd.Parameters.AddWithValue(&#34;@Prdno&#34;, prdno); cmd.ExecuteNonQuery(); } con.Close(); } }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/197994/Insert-Data-into-Parent-and-Child-Tables-from-GridView-using-C-in-ASPNet/https://www.aspforums.net:443/Threads/197994/Insert-Data-into-Parent-and-Child-Tables-from-GridView-using-C-in-ASPNet/Fri, 16 Aug 2019 01:39:19 GMT