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
Kunal VaishyaPosted Jul 19, 2013, 12:34 AM
Iftikar HussainPosted Jul 18, 2013, 11:31 PM
Try like this
Regards,
Iftikar
Jignesh TrivediPosted Jul 18, 2013, 11:10 PM
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.