using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace testingdatabase
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
new Form1().Show();
this.Close();
}
private void text_searchstring_TextChanged(object sender, EventArgs e)
{
}
private void button1_search_Click(object sender, EventArgs e)
{
errorProvider1.Dispose();
//if (.Text.Length == 0)
if (text_searchstring.Text.Length == 0)
errorProvider1.SetError(text_searchstring, "please fill name");
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\jumbo\my documents\visual studio 2010\Projects\testingdatabase\testingdatabase\Database1.mdf;Integrated Security=True;User Instance=True";
conn.Open();
//SqlCommand cmd = new SqlCommand();
//cmd.Connection = conn;
//cmd = new SqlCommand("select * from Table where name like '%" + txtsearch.Text + "%'");
//cmd = new SqlCommand("select * from Table1 where name like '%" + text_searchstring.Text + "%'");
SqlDataAdapter adapter = new SqlDataAdapter("select * from Table1 where Name like '%" + text_searchstring.Text + "%'" '%" + comboBox1.SelectedItem.ToString + "%' , conn);
DataTable dt = new DataTable();
//SqlDataAdapter adapter = new SqlDataAdapter();
adapter.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.Visible = true;
//dataGridView1.DataSource = dt;
//dataGridView1.Visible = true;
conn.Close();
conn.Dispose();
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection myConnection_Company = new SqlConnection();
myConnection_Company.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\jumbo\my documents\visual studio 2010\Projects\testingdatabase\testingdatabase\Database1.mdf;Integrated Security=True;User Instance=True";
myConnection_Company.Open();
SqlDataAdapter company = new SqlDataAdapter("select * from Table1 where Name like '" + comboBox1.SelectedItem.ToString() + "'", myConnection_Company);
//DataTable dd = new DataTable();
DataSet dd = new DataSet();
company.Fill(dd);
text_searchstring.Text = "";
myConnection_Company.Close();
myConnection_Company.Dispose();
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
}
}
hi guys,
i have a search form, which function is to search from database and show results in gridview, in this there are two boxes one is textbox and second is combobox, now in this one has to enter something in textbox and then select appropriate parameters from combobox as combobox is having some parammeters like name RollNo etc, and then the press search button for results. now issue m facing is, i am not able to use parameters of combobox and textbox together, means the search button should be able to check both boxes and then give results accordingly