Get data from sql table using c#


        protected void btnGetData_Click(object sender, EventArgs e)
        {
            string ConnectionString = "server=*********; uid=*****; pwd=*****; database=*********";
           try
           {
               DataTable dataTable = new DataTable();
               SqlConnection conn = new SqlConnection(ConnectionString);
               SqlCommand cmd = new SqlCommand("select * from Hyperlinks", conn);
               conn.Open();
               SqlDataAdapter da = new SqlDataAdapter(cmd);
               da.Fill(dataTable);
               int i = 0;
               foreach (var data in dataTable.Rows)
               {
                   string names = dataTable.Rows[i++]["Hyperlinks"].ToString();
               }
               conn.Close();
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

Comments

Popular posts from this blog

Sending email using Powershell script

Convert List Collection to DataTable using C#

Difference Between Site Template and Site Definition