2016-04-06 11 views
0

私はタブコントロールを持っています。それは9個のタブページコレクションを持っています。各タブページには、データグリッドビューと検索ボックスがあります。データグリッドビューのデータをクリアする

private void txtsrchesd_TextChanged(object sender, EventArgs e) 
{ 
    if (txtsrchesd.Text == "") 
    { 

    } 
    else 
    { 
     string constring = @"Data Source=JAY\J_SQLSERVER;Initial Catalog=FillingDatabase;User ID=jay;Password=pass1234"; 
     string query = " SELECT * FROM esd_view where department like '" + txtsrchesd.Text + "%' order by department "; 

     SqlConnection scon = new SqlConnection(constring); 
     SqlCommand cmd = new SqlCommand(query, scon); 
     SqlDataReader dr; 
     DataTable dt = new DataTable(); 
     SqlDataAdapter sql = new SqlDataAdapter(query, scon); 
     sql.Fill(dt); 
     sql.Dispose(); 

     dgesd.DataSource = dt; 

     memoDatabaseDataSetBindingSource.DataSource = dt.DefaultView; 

    } 
} 
private void txtsrchope_TextChanged(object sender, EventArgs e) 
{ 
    if (txtsrchope.Text == "") 
    { 

    } 
    else 
    { 
     string constring = @"Data Source=JAY\J_SQLSERVER;Initial Catalog=FillingDatabase;User ID=jay;Password=pass1234"; 
     string query = " SELECT * FROM operations_view where department like '" + txtsrchope.Text + "%' order by department "; 

     SqlConnection scon = new SqlConnection(constring); 
     SqlCommand cmd = new SqlCommand(query, scon); 
     SqlDataReader dr; 
     DataTable dt = new DataTable(); 
     SqlDataAdapter sql = new SqlDataAdapter(query, scon); 
     sql.Fill(dt); 
     sql.Dispose(); 

     dgoper.DataSource = dt; 

     memoDatabaseDataSetBindingSource.DataSource = dt.DefaultView; 

    } 
} 

私は

はあなたが理解してほしい私の検索ボックスに入力する内容クリアするように、他のDataGridViewの出力が他のDataGridViewに表示され、どのように私は助けてくれてありがとう、DataGridViewのの出力をクリアすることができます

+1

をあなたの質問は何ですか? –

+0

@ S.Akbari、どのように私は私の検索ボックスに何を入力するのをクリアすると、DataGridViewの出力をクリアすることができますか? – mhitzsuiko

+0

テキストボックスのいずれかに値がない場合、データグリッドビューにデータがないようにしたいですか?この回答をご覧ください: http://stackoverflow.com/questions/13137591/how-to-clear-a-data-grid-view – Draken

答えて

0

あなたがチェックしている:他には

{ 
    if (txtsrchope.Text != "") 
    {} 
    ..... 
} 

あなたはときと同じクエリを発射する必要はありません一部:

txtsrchop.text =="" 

あなたは、このコードによって、あなたの他の部品を交換することができます

else 
{ 
    string constring = @"Data Source=JAY\J_SQLSERVER;Initial Catalog=FillingDatabase;User ID=jay;Password=pass1234"; 
     string query = " SELECT * FROM operations_view "; 

    SqlConnection scon = new SqlConnection(constring); 
    SqlCommand cmd = new SqlCommand(query, scon); 
    SqlDataReader dr; 
    DataTable dt = new DataTable(); 
    SqlDataAdapter sql = new SqlDataAdapter(query, scon); 
    sql.Fill(dt); 
    sql.Dispose(); 

    dgoper.DataSource = dt; 

    memoDatabaseDataSetBindingSource.DataSource = dt.DefaultView; 

} 
関連する問題