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.Replace save database query variable with value using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="alya14"> alya14</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:Button Text=&#34;Save&#34; runat=&#34;server&#34; OnClick=&#34;Save&#34; /&gt; &lt;br /&gt; &lt;asp:Label ID=&#34;lblQuery&#34; runat=&#34;server&#34; /&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Configuration; using System.Data.SqlClient; </pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data.SqlClient</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Save(object sender, EventArgs e) { var query = &#34;SELECT Query FROM StoreQuery&#34;; GetName(query); lblQuery.Text = GetName(query).Replace(&#34;\&#34;&#34;, &#34;&#34;).Replace(&#34;+&#34;, &#34;&#34;).Replace(&#34;PLN&#34;, &#34;aly&#34;); } private string GetName(string query) { string name = &#34;&#34;; string conString = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(conString)) { using (SqlCommand cmd = new SqlCommand(query, con)) { con.Open(); name = cmd.ExecuteScalar().ToString(); con.Close(); } } return name; }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Save(ByVal sender As Object, ByVal e As EventArgs) Dim query = &#34;SELECT Query FROM StoreQuery&#34; GetName(query) lblQuery.Text = GetName(query).Replace(&#34;&#34;&#34;&#34;, &#34;&#34;).Replace(&#34;+&#34;, &#34;&#34;).Replace(&#34;PLN&#34;, &#34;aly&#34;) End Sub Private Function GetName(ByVal query As String) As String Dim name As String = &#34;&#34; Dim conString As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Using con As SqlConnection = New SqlConnection(conString) Using cmd As SqlCommand = New SqlCommand(query, con) con.Open() name = cmd.ExecuteScalar().ToString() con.Close() End Using End Using Return name End Function</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/9M37Otv.jpg" alt="" width="435" height="211" /></p>https://www.aspforums.net:443/Threads/765376/Replace-save-database-query-variable-with-value-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/765376/Replace-save-database-query-variable-with-value-using-C-and-VBNet-in-ASPNet/Thu, 09 May 2019 07:00:00 GMTReplace save database query variable with value using C# and VB.Net in ASP.Net<p>I solved this issue using parameters like&nbsp;bellow</p> <p>I stored like this WHERE CODE=@P1</p> <p>and call</p> <p>cmd.parameters.addwithvalue("@P1",PLN)</p> <p>Thanks for your time.</p> <p>&nbsp;</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/765376/Replace-save-database-query-variable-with-value-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/765376/Replace-save-database-query-variable-with-value-using-C-and-VBNet-in-ASPNet/Mon, 13 May 2019 04:25:19 GMT