Get the Table's Column information using this code.Schema Table contains all the information about the Table's Column...........
using System;
using System.Data;
using System.Data.SqlClient;
namespace GetSchemaInfo
{
public class TableSchmea
{
string hi;
public string FindMaxLength(string tablename,string fieldname)
{
SqlConnection Conn = new SqlConnection("server=210.210.99.104;database=IndageLive;uid=shaw;pwd=shaw;");
SqlCommand Cmd = new SqlCommand("Select * from "+tablename,Conn);
Conn.Open();
SqlDataReader dr = Cmd.ExecuteReader();
DataTable SchemaTable = dr.GetSchemaTable();
foreach(DataRow drow in SchemaTable.Rows)
{
foreach(DataColumn dcol in SchemaTable.Columns)
{
if(dcol.ColumnName == "ColumnName" && drow[dcol].ToString()== fieldname)
{
hi = dcol.ColumnName +" = "+ drow[dcol] +" "+ "ColumnSize " + "=" + drow["ColumnSize"] ;
}
}
}
//Console.ReadLine();
dr.Close();
Conn.Close();
return hi;
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment