日期:2014-05-19  浏览次数:20876 次

怎样获取一张表里所有字段
哪位高手进来指点下啊.
C#中怎样获取一张表里所有字段

------解决方案--------------------
using System.Data.SqlClient;
SqlConnection con = new SqlConnection();
con.ConnectionString = "Persist Security Info=false;Initial Catalog=ycqry2;User Id=sa;Password=;server= " + DB.LoginServer();

con.Open();

int year = System.DateTime.Now.Year;

//不同年对应的用友数据库
string UFDFcode= "select * from UFDFcode where cYear= "+year;
SqlCommand cmdUFDAcode = new SqlCommand(UFDFcode, con);
SqlDataReader drUFDFcode = cmdUFDAcode.ExecuteReader();

string UFDatabaseOld = " ";
string UFDatabaseNew = " ";
while (drUFDFcode.Read())
{
UFDatabaseOld=drUFDFcode.GetString(1);
UFDatabaseNew=drUFDFcode.GetString(2);
}
drUFDFcode.Close();


------解决方案--------------------
问题讲明白了吗??
------解决方案--------------------
select * from table
------解决方案--------------------
select * from table
------解决方案--------------------
SELECT TABLE_CATALOG AS [Database], TABLE_SCHEMA AS Owner, TABLE_NAME AS TableName, COLUMN_NAME AS ColumnName, ORDINAL_POSITION AS OrdinalPosition, COLUMN_DEFAULT AS DefaultSetting, IS_NULLABLE AS IsNullable, DATA_TYPE AS DataType, CHARACTER_MAXIMUM_LENGTH AS MaxLength, DATETIME_PRECISION AS DatePrecision,COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity ') as IsIdentity
FROM INFORMATION_SCHEMA.COLUMNS WHERE (TABLE_NAME = '表名 ')
------解决方案--------------------
SELECT TableColumns.Name ColumnName
FROM SYSOBJECTS Tables, SYSCOLUMNS TableColumns
WHERE Tables.ID = TableColumns.ID
AND Tables.Name = '表名 '
------解决方案--------------------
select name from syscolumns where id=object_id( 'table ')

------解决方案--------------------
up
大家的都是SQL语句
楼主是想问C#这样连接数据库吧!
------解决方案--------------------
推荐 popeye627(一曲肝肠断,天涯何处觅知音?) 的

select name from syscolumns where id=object_id( 'table ')