如何创建方法..... [英] how to create method.....

查看:66
本文介绍了如何创建方法.....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建方法使用datatable将新列添加到现有表中我的数据库plz解决此问题

how to create method add new column to a existing table using datatable into my database plz solve this problem

推荐答案

引用:

我想在将excel文件导入表格时,在我的数据库表中添加新列,如唯一ID(主键),然后自动为表格生成新的添加列(唯一ID)

i want to add new column in my database table like unique id (primary key ) when import excel file to a table then automatic generate new add column to a table (unique id )

然后添加一个列并使其自动增加。



参考 - SQL自动增量字段 [ ^ ]

Then add one Column and make it Auto-Incremented.

Refer - SQL AUTO INCREMENT Field[^]


由于您使用 SqlBulkCopy ,您可以在目标表中创建自动增量列,并将所有列映射添加到其他列。当您选择数据时,您可以在调用 WriteToServer 时提供列名称和添加映射。例如

Since you are using SqlBulkCopy you can create auto increment column in destination table and all add column mappings to other columns. when you select data, you can give columns names and add mappings when you call WriteToServer. for example
SqlCommand cmd = new SqlCommand("select column1, columns2 from tbdata", con);



然后是映射


then the mappings

SqlBulkCopy bulkInsert = new SqlBulkCopy(con_str);
bulkInsert.DestinationTableName = "tbdata";
bulkInsert.ColumnMappings.Add("column1", "column1");
bulkInsert.ColumnMappings.Add("columns2 ", "columns2");


这篇关于如何创建方法.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆