MappingTableAddColumnNames
2010-05-27 21:09
211 查看
namespace MappingTableAddColumnNames
{
class Program
{
static void Main(string[] args)
{
string sqlconnectionstring = "Data source=王俊俊-PC//SQLEXPRESS;Initial Catalog=classtest;Integrated Security=True";
string sqlcommandstring=" select userid, usernaem,useraddress from userinfo";
SqlConnection conn = new SqlConnection(sqlconnectionstring );
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(sqlcommandstring, conn);
DataTableMapping dtm = da.TableMappings.Add("UserInfo", "mappedContact");
dtm.ColumnMappings.Add("userid", "mappeduserid");
dtm.ColumnMappings.Add("username", "mappedusername");
dtm.ColumnMappings.Add("useraddress", "mappeduseraddress");
DataSet ds = new DataSet();
da.Fill(ds);
Console.WriteLine("DataTable name={0}",ds.Tables [0].TableName );
foreach (DataColumn col in ds.Tables["mappedContact"].Columns)
{
Console.WriteLine("/tDataColumn{0} name={1}",col.Ordinal ,col.ColumnName );
}
}
}
}
{
class Program
{
static void Main(string[] args)
{
string sqlconnectionstring = "Data source=王俊俊-PC//SQLEXPRESS;Initial Catalog=classtest;Integrated Security=True";
string sqlcommandstring=" select userid, usernaem,useraddress from userinfo";
SqlConnection conn = new SqlConnection(sqlconnectionstring );
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(sqlcommandstring, conn);
DataTableMapping dtm = da.TableMappings.Add("UserInfo", "mappedContact");
dtm.ColumnMappings.Add("userid", "mappeduserid");
dtm.ColumnMappings.Add("username", "mappedusername");
dtm.ColumnMappings.Add("useraddress", "mappeduseraddress");
DataSet ds = new DataSet();
da.Fill(ds);
Console.WriteLine("DataTable name={0}",ds.Tables [0].TableName );
foreach (DataColumn col in ds.Tables["mappedContact"].Columns)
{
Console.WriteLine("/tDataColumn{0} name={1}",col.Ordinal ,col.ColumnName );
}
}
}
}
相关文章推荐
- @Table(name = "", uniqueConstraints = @UniqueConstraint(columnNames = ""))
- ORA-01758: table must be empty to add mandatory (NOT NULL) column
- Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn
- Sybase add/delete column from table
- Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -
- add column for a table if this column not exists using T-SQL in SQLServer
- @Table(name = "", uniqueConstraints = @UniqueConstraint(columnNames = ""))
- faster alter table add column
- Mysql官方文档中争对安全添加列的处理方法。Mysql Add a Column to a table if not exists
- (add comment to table or column,and add comment to ddl script) erwin为ddl script 脚本添加表或字段的注释(导出注释)(comment)
- @Table(name = "", uniqueConstraints = @UniqueConstraint(columnNames = ""))
- @Table(name = "", uniqueConstraints = @UniqueConstraint(columnNames = ""))
- GP BUG APPEND TABLE ADD COLUMN
- Hive查询报错 Invalid table alias or column reference 'create_time': (possible column names are: _c0, _c1
- Oracle alter table add column example
- 解决:Reading table information for completion of table and column names
- MySQL How to add a column in a table?
- @Table(name = "", uniqueConstraints = @UniqueConstraint(columnNames = ""))
- @Table(name = "", uniqueConstraints = @UniqueConstraint(columnNames = ""))
- Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A