Databind Dynamic Control Type And Name

Im working on a method to make all my SQL Querys and then databind them to Repeaters, DataLists And so on...\[code\]protected void sqlQuery(Control controlName, String query) { SqlConnection conn = new SqlConnection(); SqlCommand cmd = new SqlCommand(); conn.ConnectionString = ConfigurationManager.ConnectionStrings["SqlConn"].ToString(); cmd.Connection = conn; try { cmd.CommandText = query; DataTable dt = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter(cmd); adapter.Fill(dt); controlName.DataSource = dt; controlName.DataBind(); } catch (Exception error) { Label1.Text = "Error!<br/>" + error; }}\[/code\]Then i would call the method with my control name that i want to databind to.Like:\[code\]sqlQuery(Repeater1, "SELECT * FROM someTable");sqlQuery(DataList1, "SELECT * FROM someTable");\[/code\]But that dosent work now since it dont know the control type when i just use Control..So how would i do this?
 
Back
Top