Saturday, May 5, 2012

View All Databases in TreeView using C#


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Examples
{
    public partial class Databases : Form
    {
        public Databases()
        {
            InitializeComponent();
        }
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=jQuery;UID=sa;password=tiger123");
        SqlCommand cmd;
        private void Databases_Load(object sender, EventArgs e)
        {
            fillTreeView();
        }
        private void fillTreeView()
        {
            try
            {
                con.Open();
                cmd = new SqlCommand("sp_helpdb", con);
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    treeView1.Nodes.Add(dr["name"].ToString());
                   
                }
            }
            catch (Exception ex)
            {
            }
        }
    }
}

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...