表从一个数据库到另一个数据库的完整副本 [英] complete copy of table from one database to another

查看:59
本文介绍了表从一个数据库到另一个数据库的完整副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的项目中,我想将表从一个访问数据库复制到另一个数据库
我正在使用此代码
查询= "SELECT * INTO tablename FROM tablename";
但它只是复制结构及其值,不复制任何扩展属性意味着有复选框作为字段值,而不是复选框将值设为-1或0.
所以请告诉我解决方案..

in our project, i want to copy a table from one access database to another
i''m using this code
query="SELECT * INTO tablename FROM tablename";
but it is only copy the structure and its value, it is not copying any extended properties means there are checkboxes as field value but instead of checkboxes it is taken value as -1 or 0.
so plz tell me the solution..

推荐答案

这是我的方法:

This is the way I do it:

SELECT * INTO NewTable FROM OldTable



我不知道为什么您的sql中有&"号,也不知道为什么要使用IN.



I don''t know why have ampersands in your sql, nor why you''re using IN.


如果问题是1或0,只需将该字段的属性更改为是/否或您想要的任何内容
if the problem is 1 Or 0 just change the properties of that filed to true/false or anything you want


你好
您还可以在给定代码的帮助下使用SQLBULKCOPY进行此操作,但是首先您必须创建表,即源表和目标表
hello
you can also use SQLBULKCOPY for this with help of given code, but first u have to create both the tables i.e. source table and destination table
//setting the connection string
string connection = "Data Source=.;Initial Catalog=master;Integrated Security=True";

            SqlConnection myconnect = new SqlConnection(connection);
            myconnect.Open(); //open the connection
            SqlCommand cmd = new SqlCommand("select * from sourcetable", myconnect);
            SqlDataReader dr = cmd.ExecuteReader();
//new connection specification
            SqlConnection con = new SqlConnection(connection);
            con.Open();
            SqlBulkCopy bulk = new SqlBulkCopy(con);
//name of the destination table where u wana copy ur data
            bulk.DestinationTableName = "desti"; 
            try
            {
                bulk.WriteToServer(dr);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Some error");
            }
            finally
            {
                dr.Close();
            }
            myconnect.Close();


            MessageBox.Show("Record Copied");



一旦找到有用的答案,就对我的答案进行评分

谢谢&问候
基数:)



Do Rate my answer once you find it useful

Thanks & Regards
Radix :)


这篇关于表从一个数据库到另一个数据库的完整副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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