private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
dataGridView1.Rows.Clear();
SqlConnection con = new SqlConnection("Data Source=" + Settings.Default.db_ip + ";Initial Catalog=" + Settings.Default.db_name + ";User Id=" + Settings.Default.db_user + ";Password=" + Settings.Default.db_pass + ";");
SqlDataAdapter tbCount = new SqlDataAdapter("USE " + Settings.Default.db_name + " SELECT * from'" + comboBox1.Text + "'", con);
DataSet dt = new DataSet();
tbCount.Fill(dt);
this.dataGridView1.DataSource = dt.Tables[0];
}
please help
Loading

Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 18, 2013, 7:10 PM EDT
hi,
Why you write sql Query like Use DatabaseName?
you are already connected to that database only which is mention in Connection string.
so I think "Use DatabaseName" is not required here.
Also if you fire more than one SQL statement with one command or Adapter than all SQL statement must be seperated by semicolumn (;)
hope this will help you.
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 18, 2013, 7:31 PM EDT
Try like this
Regards,
Iftikar
Kunal VaishyaRank #990 · 2K reputationPosted Jul 18, 2013, 8:34 PM EDT