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.Open Windows Form based on Database record on ToolStripMenuItem Click using C# and VB.Net <p>Hey <a class="username" rel="PRA"> PRA</a>,</p> <p>Please refer below smaple.</p> <p>Use dropdownItemClicked Event.</p> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">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">private void mainMenuToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { string submenu = e.ClickedItem.Text; string constr = @&#34;Server=.\SQL2005;DataBase=Test;UID=sa;PWD=pass@123&#34;; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(&#34;SELECT Title FROM Menus WHERE Title=@Title&#34;, con)) { cmd.Parameters.AddWithValue(&#34;@Title&#34;, submenu); con.Open(); string menuItemName = Convert.ToString(cmd.ExecuteScalar()); if (menuItemName == submenu) { Form2 f2 = new Form2(); f2.ShowDialog(); } else { MessageBox.Show(&#34;You haven&#39;t access to this form!&#34;); } con.Close(); } } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Private Sub MainMenuToolStripMenuItem_DropDownItemClicked_1(sender As System.Object, e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MainMenuToolStripMenuItem.DropDownItemClicked Dim submenu As String = e.ClickedItem.Text Dim constr As String = &#34;Server=.\SQL2005;DataBase=Test;UID=sa;PWD=pass@123&#34; Using con As SqlConnection = New SqlConnection(constr) Using cmd As SqlCommand = New SqlCommand(&#34;SELECT Title FROM Menus WHERE Title=@Title&#34;, con) cmd.Parameters.AddWithValue(&#34;@Title&#34;, submenu) con.Open() Dim menuItemName As String = Convert.ToString(cmd.ExecuteScalar()) If menuItemName = submenu Then Dim f2 As Form2 = New Form2() f2.ShowDialog() Else MessageBox.Show(&#34;You haven&#39;t access to this form!&#34;) End If con.Close() End Using End Using End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://imgur.com/rPqfFjc.gif" alt="" width="305" height="308" /></p>https://www.aspforums.net:443/Threads/497097/Open-Windows-Form-based-on-Database-record-on-ToolStripMenuItem-Click-using-C-and-VBNet/https://www.aspforums.net:443/Threads/497097/Open-Windows-Form-based-on-Database-record-on-ToolStripMenuItem-Click-using-C-and-VBNet/Wed, 05 Dec 2018 00:52:26 GMT