SQL Requests. Working with text boxes

Not working request. What could be the problem? Before that he wrote through CommandText, all worked well.

Code:

        private void buttonSearch_Click(object sender, EventArgs e)
    {
        string constring = @"Data Source=(LocalDB)v11.0;AttachDbFilename=C:UsersHomePCDesktopLab2 DBLab2 DBResearchDB.mdf;Integrated Security=True";
        using (SqlConnection con = new SqlConnection(constring))
        {
            using (SqlCommand cmd = new SqlCommand("SELECT * FROM '"+comboBox1.SelectedItem.ToString()+"' WHERE '"+ comboBox2.SelectedItem.ToString() +"' = '"+ textBox1.Text +"'", con))
            {
                cmd.CommandType = CommandType.Text;
                using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                {
                    using (DataTable dt = new DataTable())
                    {
                        sda.Fill(dt);
                        dataGridView1.DataSource = dt;
                    }
                }
            }
        }
    }


Source: sql

Leave a Reply