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 double quotes when selected DropDownList is blank using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="democloud"> democloud</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;label&gt; Type&lt;/label&gt; &lt;asp:DropDownList ID=&#34;DropDownList1&#34; class=&#34;form-control&#34; runat=&#34;server&#34; OnSelectedIndexChanged=&#34;Insert&#34; AutoPostBack=&#34;true&#34;&gt; &lt;asp:ListItem Value=&#34;0&#34; Text=&#34;Blank&#34;&gt;Blank&lt;/asp:ListItem&gt; &lt;asp:ListItem Value=&#34;1&#34; Text=&#34;CANC&#34;&gt;A&lt;/asp:ListItem&gt; &lt;asp:ListItem Value=&#34;2&#34; Text=&#34;B&#34;&gt;REPW&lt;/asp:ListItem&gt; &lt;asp:ListItem Value=&#34;3&#34; Text=&#34;C&#34;&gt;TRAN&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&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 Insert(object sender, EventArgs e) { string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(&#34;INSERT INTO TestDeom VALUES(@typeData)&#34;, con); if (DropDownList1.SelectedItem.Text == &#34;Blank&#34;) { cmd.Parameters.AddWithValue(&#34;@typeData&#34;, &#34;\&#34;\&#34;&#34;); } else { cmd.Parameters.AddWithValue(&#34;@typeData&#34;, DropDownList1.SelectedItem.Text); } con.Open(); cmd.ExecuteNonQuery(); con.Close(); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Insert(ByVal sender As Object, ByVal e As EventArgs) Dim constr As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Dim con As SqlConnection = New SqlConnection(constr) Dim cmd As SqlCommand = New SqlCommand(&#34;INSERT INTO TestDeom VALUES(@typeData)&#34;, con) If DropDownList1.SelectedItem.Text = &#34;Blank&#34; Then cmd.Parameters.AddWithValue(&#34;@typeData&#34;, &#34;&#34;&#34;&#34;&#34;&#34;) Else cmd.Parameters.AddWithValue(&#34;@typeData&#34;, DropDownList1.SelectedItem.Text) End If con.Open() cmd.ExecuteNonQuery() con.Close() End Sub</pre>https://www.aspforums.net:443/Threads/360666/Insert-double-quotes-when-selected-DropDownList-is-blank-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/360666/Insert-double-quotes-when-selected-DropDownList-is-blank-using-C-and-VBNet-in-ASPNet/Fri, 15 Feb 2019 04:07:46 GMT