Hello Sirs/Madams,
I had created a form in which, I had inserted a DataGridView. And aslo I am having the "
first
,
middle
and
last
" labels with there TextBoxes and one search Button. So what I want is, if I enter the name in TextBox of "
first
" label and hit a search button, its row as to be displayed in DataGridView.
So I have to add the query in "DataGridView Task", or I have to write query inside "
GridView
".
This is my code:
namespace Config_admin
{
public partial class Form2 : Form
{
SqlConnection con;
SqlCommand com;
SqlDataReader rdr;
DataSet ds;
SqlDataAdapter da;
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
con = new SqlConnection("Data Source=CBP\\SQLEXPRESS;Initial Catalog=ECG;Integrated Security=True");
con.Open();
com = new SqlCommand("select middle,last from Table2 where first= '"+ textBox1.Text.Trim()+"'",con);
rdr = com.ExecuteReader();
bool temp = false;
while (rdr.Read())
{
comboBox1.Text = rdr[0].ToString().Trim();
comboBox2.Text = rdr[1].ToString().Trim();
temp = true;
}
if (temp == false)
MessageBox.Show("not found");
con.Close();
con.Open();
ds = new DataSet();
da = new SqlDataAdapter("select * from Table2", con);
da.Fill(ds, "Table2");
con.Close();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
Please help me in this regard
Thanks
Pradeep CBZ