How to Get Table Information in ASP .NET


Unknown | 05:52 |

How to Get Table Information in ASP .NET


using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection newConnection = new
SqlConnection(@"Data Source=R4R-3EFD13BB468\SQLEXPRESS;
initial catalog=newDatabase;integrated security=true;"
);
protected void Page_Load(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("SELECT TABLE_TYPE,
TABLE_NAME FROM INFORMATION_SCHEMA.TABLES"
, newConnection);
newConnection.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Label1.Text ="Table Type: "+dr[0].ToString();
Label2.Text = "Table Name: "+dr[1].ToString();
}
newConnection.Close();
}
}

Out Put:

0 comments:

Post a Comment