Matt Butler

Matt Butler

  • NA
  • 18
  • 0

Can't use '+' to append text??

Oct 29 2010 3:49 PM
I am using the following code to attempt to get a list of tables from a list of databases that I previously fetched. I cannot get the tables to work because I cannot split the connection string for some odd reason. I should tell you that I am very new to C#. I was taking Java at school and decided that C# was much better for me.

This is the code to get my list of databases from the SQL server:
 
        private void frmImport_Load(object sender, EventArgs e)
        {
           
            comboBox2.Items.Clear();
            SqlConnection SqlConn = new SqlConnection("Data Source=10.100.1.6; Trusted_Connection=True;");
            SqlConn.Open();
       
            SqlCommand SqlCom = new SqlCommand();
            SqlCom.Connection = SqlConn;
            SqlCom.CommandType = CommandType.StoredProcedure;
            SqlCom.CommandText = "sp_databases";
       
            SqlDataReader SqlDR;
            SqlDR=SqlCom.ExecuteReader();
       
            while (SqlDR.Read())
            {
                comboBox1.Items.Add(SqlDR.GetString(0));
            }
        }


This is my code to get the tables from the database that I just fetched:
         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox2.Items.Clear();
            SqlConnection SqlConn = new SqlConnection("Data Source=10.100.1.6; Initial Catalog=" +comboBox1.SelectedItem.ToString +";Trusted_Connection=True;");
            SqlConn.Open();

            SqlCommand SqlCom = new SqlCommand();
            SqlCom.Connection = SqlConn;
            SqlCom.CommandType = CommandType.StoredProcedure;
            SqlCom.CommandText = "sp_tables";

            SqlDataReader SqlDR;
            SqlDR = SqlCom.ExecuteReader();

            while (SqlDR.Read())
            {
                comboBox2.Items.Add(SqlDR.GetString(0));
            }
        }


I having a problem with the second line. I am getting this error:
 Error    1    Operator '+' cannot be applied to operands of type 'string' and 'method group'

Any help you can provide me would be greatly appreciated.

Kind Regards

Answers (3)