First of all, NEVER build a command like this:
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO Table1 (Company_Name) VALUES ('" + TxtName.Text + "')";
Doing this exposes you to sql injection vulnerabilities. Instead, do this:
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO Table1 (Company_Name) VALUES (@compName)";
cmd.Parameters.AddWithValue("@compName", TxtName.Text);
In regards to where to add this code, that all depends on your code. Ideally, you want to seperate your data access, business logic and presentation layers (n-Tier architecture). There are many artciles on the web that explain this architecture. Below are some articles that can help you get started:
Since you seem like you are a beginner, for testing and learning purposes, you can do this, however, I do not recommend the below method:
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO Table1 (Company_Name) VALUES (@compName)";
foreach (DataRow row in dt.Rows)
{
cmd.Parameter.AddWithValue("@compName", row["name"].ToString());
cmd.ExecuteNonQuery();
}
After all your inserts are done, don't forget to clean up after yourself. Dispose of the objects you are done with (cmd, conn..)
cmd.Dispose();
conn.Close();
conn.Dispose();