How do I connect gridview to sql using C# in asp.net?
<p>I know how to connect, open, read, close as you see below.  I also have awesome tutorial how to add update/delete etc.  </p>

<p>I can connect dataTable to sql using asp.net controls, but I want to learn how to manipulate it from C#.</p>

<p>MasterCust is my gridview table name.  How do I connect the to it?</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection Conn = new SqlConnection("Data Source=aserver;Initial Catalog=KennyCust;Persist Security Info=True;user id=sa;pwd=qwerty01");
        SqlDataReader rdr = null;
        string commandString = "SELECT * FROM MainDB";

        try
        {
            Conn.Open();
            SqlCommand Cmd = new SqlCommand(commandString, Conn);

            rdr = Cmd.ExecuteReader();

            while (rdr.Read())
            {
                Console.WriteLine(rdr[0]);
            }
        }
        finally
        {
            if (rdr != null)
            {
                rdr.Close();
            }
            if (Conn != null)
            {
                Conn.Close();
            }
        }
        //MasterCust.
        //MasterCust.DataSource = commandString;
        //MasterCust.DataBind();
    }
</code></pre>

<p>Edit:  This code worked</p>

<pre><code>            try
        {
            Conn.Open();
            SqlCommand Cmd = new SqlCommand(commandString, Conn);
            SqlDataAdapter sdp = new SqlDataAdapter(Cmd);
            DataSet ds = new DataSet();

            sdp.Fill(ds);
            //rdr = Cmd.ExecuteReader();
            MasterCust.DataSource = ds.Tables[0];
            MasterCust.DataBind();


            }
</code></pre>
