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.Send parameters to ASP.Net SqlDataSource from class file using C#<p>Hey&nbsp;<a class="username" rel="dorsa">dorsa,</a></p> <p>Please refer below sample.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:SqlDataSource ID=&#34;sqlDtSrcEmployees&#34; runat=&#34;server&#34; ConnectionString=&#34;&lt;%$ ConnectionStrings:constr %&gt;&#34; SelectCommand=&#34;SELECT * FROM [Customers]&#34; InsertCommand=&#34;INSERT INTO [Customers] ([Name], [Country]) VALUES (@Name, @Country)&#34;&gt; &lt;InsertParameters&gt; &lt;asp:ControlParameter ControlID=&#34;txtName&#34; Name=&#34;Name&#34; PropertyName=&#34;Text&#34; Type=&#34;String&#34; /&gt; &lt;asp:ControlParameter ControlID=&#34;txtCountry&#34; Name=&#34;Country&#34; PropertyName=&#34;Text&#34; Type=&#34;String&#34; /&gt; &lt;/InsertParameters&gt; &lt;/asp:SqlDataSource&gt; Name: &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtName&#34; /&gt; Country: &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtCountry&#34; /&gt; &lt;asp:Button Text=&#34;Insert&#34; runat=&#34;server&#34; OnClick=&#34;Insert&#34; /&gt;</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>Person.cs</strong></p> <pre class="brush: csharp">public class Person { public string Name(string namee) { string name = namee; return name; } public string Country(string countri) { string country = countri; return country; } }</pre> <p><strong>CS.aspx.cs</strong></p> <pre class="brush: csharp">protected void Insert(object sender, EventArgs e) { sqlDtSrcEmployees.Insert(); } protected void sqlDtSrcEmployees_Inserting(object sender, SqlDataSourceCommandEventArgs e) { Person p = new Person(); string name = p.Name(txtName.Text); string country = p.Country(txtCountry.Text); e.Command.Parameters[&#34;@Name&#34;].Value = name; e.Command.Parameters[&#34;@Country&#34;].Value = country; }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/149889/Send-parameters-to-ASPNet-SqlDataSource-from-class-file-using-C/https://www.aspforums.net:443/Threads/149889/Send-parameters-to-ASPNet-SqlDataSource-from-class-file-using-C/Mon, 17 Dec 2018 02:13:07 GMT