1、使用Microsoft SQL Server Manager Studio登录数据库。
2、在左边树找到要查的表,并点击前边的“+”
3、点击“列”前边的“+”
代码如下:
/// <summary>/// 取所有表名
/// </summary>
/// <returns></returns>
public List<string> GetTableNameList()
{
List<string> list = new List<string>()
OleDbConnection Conn = new OleDbConnection(ConnStr)
try
{
if (Conn.State == ConnectionState.Closed)
Conn.Open()
DataTable dt = Conn.GetSchema("Tables")
foreach (DataRow row in dt.Rows)
{
if (row[3].ToString() == "TABLE")
list.Add(row[2].ToString())
}
return list
}
catch (Exception e)
{ throw e }
finally { if (Conn.State == ConnectionState.Open) Conn.Close() Conn.Dispose() }
}
/// <summary>
/// 取指定表所有字段名称
/// </summary>
/// <returns></returns>
public List<string> GetTableFieldNameList(string TableName)
{
List<string> list = new List<string>()
OleDbConnection Conn = new OleDbConnection(ConnStr)
try
{
if (Conn.State == ConnectionState.Closed)
Conn.Open()
using (OleDbCommand cmd = new OleDbCommand())
{
cmd.CommandText = "SELECT TOP 1 * FROM [" + TableName + "]"
cmd.Connection = Conn
OleDbDataReader dr = cmd.ExecuteReader()
for (int i = 0 i < dr.FieldCount i++)
{
list.Add(dr.GetName(i))
}
}
return list
}
catch (Exception e)
{ throw e }
finally
{
if (Conn.State == ConnectionState.Open)
Conn.Close()
Conn.Dispose()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)