Question: C# .Net framework when I click search button display a datagridview in the same form I need that datagridview.datasource = dt; display in different form
C# .Net framework when I click search button display a datagridview in the same form I need that datagridview.datasource = dt; display in different form or another form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Accounts
{
public partial class MENU : Form
{
public MENU()
{
InitializeComponent();
}
private void MENU_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'accounts2022DataSet11.Account' table. You can move, or remove it, as needed.
this.accountTableAdapter.Fill(this.accounts2022DataSet11.Account);
// TODO: This line of code loads data into the 'accounts2022DataSet1.Account' table. You can move, or remove it, as needed.
this.accountTableAdapter.Fill(this.accounts2022DataSet1.Account);
}
private void button_clear_menu_Click(object sender, EventArgs e)
{
textBox_id_menu.Clear();
textBox_user_menu.Clear();
textBox_password_menu.Clear();
textBox_url_menu.Clear();
textBox_host_menu.Clear();
textBox_service_menu.Clear();
textBox_scv_menu.Clear();
textBox_id_menu.Focus();
dataGridView1.Refresh();
}
private void button_exit_menu_Click(object sender, EventArgs e)
{
DialogResult result;
result = MessageBox.Show("Do you want to exit? ", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
Application.Exit();
}
else
{
this.Show();
}
}
private void button_viewall_Click(object sender, EventArgs e)
{
viewAll form3 = new viewAll();
form3.Show();
this.Hide();
}
private void button_search_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"**********Icant show this***********");
DataTable dt = new DataTable();
if (textBox_user_menu.Text.Length > 0)
{
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Account WHERE UserName LIKE '"+ textBox_user_menu.Text + "%'",conn);
sda.Fill(dt);
}
else if (textBox_password_menu.Text.Length > 0)
{
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Account WHERE Password LIKE '" + textBox_password_menu.Text + "%'", conn);
sda.Fill(dt);
}
else if (textBox_url_menu.Text.Length > 0) {
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Account WHERE URL LIKE '" +textBox_url_menu.Text + "%'", conn);
sda.Fill(dt);
}
else if (textBox_host_menu.Text.Length > 0)
{
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Account WHERE HostName LIKE '" + textBox_host_menu.Text + "%'", conn);
sda.Fill(dt);
}
else if (textBox_service_menu.Text.Length > 0)
{
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Account WHERE ServiceName LIKE '" + textBox_service_menu.Text + "%'", conn);
sda.Fill(dt);
}
else if (textBox_scv_menu.Text.Length > 0)
{
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Account WHERE SvcTypeName LIKE '" + textBox_scv_menu.Text + "%'", conn);
sda.Fill(dt);
}
else if (textBox_id_menu.Text.Length > 0)
{
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Account WHERE AccountID LIKE '" + textBox_id_menu.Text + "%'", conn);
sda.Fill(dt);
}
dataGridView1.DataSource = dt;=====================>here is where I need to show in different form
}
private void textBox_id_menu_TextChanged(object sender, EventArgs e)
{
textBox_user_menu.Text = "";
textBox_password_menu.Text = "";
textBox_url_menu.Text = "";
textBox_host_menu.Text = "";
textBox_service_menu.Text = "";
textBox_scv_menu.Text = "";
}
private void textBox_user_menu_TextChanged(object sender, EventArgs e)
{
textBox_password_menu.Text = "";
textBox_url_menu.Text = "";
textBox_host_menu.Text = "";
textBox_service_menu.Text = "";
textBox_scv_menu.Text = "";
textBox_id_menu.Text = "";
}
private void textBox_password_menu_TextChanged(object sender, EventArgs e)
{
textBox_url_menu.Text = "";
textBox_host_menu.Text = "";
textBox_service_menu.Text = "";
textBox_scv_menu.Text = "";
textBox_id_menu.Text = "";
textBox_user_menu.Text = "";
}
private void textBox_url_menu_TextChanged(object sender, EventArgs e)
{
textBox_host_menu.Text = "";
textBox_service_menu.Text = "";
textBox_scv_menu.Text = "";
textBox_id_menu.Text = "";
textBox_user_menu.Text = "";
textBox_password_menu.Text = "";
}
private void textBox_host_menu_TextChanged(object sender, EventArgs e)
{
textBox_service_menu.Text = "";
textBox_scv_menu.Text = "";
textBox_id_menu.Text = "";
textBox_user_menu.Text = "";
textBox_password_menu.Text = "";
textBox_url_menu.Text = "";
}
private void textBox_service_menu_TextChanged(object sender, EventArgs e)
{
textBox_scv_menu.Text = "";
textBox_id_menu.Text = "";
textBox_user_menu.Text = "";
textBox_password_menu.Text = "";
textBox_url_menu.Text = "";
textBox_host_menu.Text = "";
}
private void textBox_scv_menu_TextChanged(object sender, EventArgs e)
{
textBox_id_menu.Text = "";
textBox_user_menu.Text = "";
textBox_password_menu.Text = "";
textBox_url_menu.Text = "";
textBox_host_menu.Text = "";
textBox_service_menu.Text = "";
}
private void button_new_Click(object sender, EventArgs e)
{
NewData form5 = new NewData();
form5.Show();
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
