Hi, since you are new to C#, You can use the below code ,what you are asking is similar to SQL Query analyser where in SQL editor you type SQL commands/statements and run to get results
Put a textbox and datagridview on windows form with button for action, and on button click event write below code, put the database connection appropriately
private void button1_Click(object sender, EventArgs e)
{
string DBCommand = textBox1.Text;
SqlDataAdapter sqlDa = new SqlDataAdapter(DBCommand, "Data Source=localhost;Initial Catalog=Northwind;User ID=sa;Password=sa");
sqlDa.Fill(ds, "Tables");
dataGridView1.DataSource = ds.Tables[0];
}