C#中有关数据库的数据转换

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.Data.SqlClient;







namespace ImportData

{

	/// <summary>

	/// Form1 的摘要说明。

	/// </summary>

	public class ImportForm : System.Windows.Forms.Form

	{

		private System.Windows.Forms.Label Namelabel;

		private System.Windows.Forms.ProgressBar ImportprogressBar;

		private System.Windows.Forms.Button Importbutton;



		/// <summary>

		/// 必需的设计器变量。

		/// </summary>

		private System.ComponentModel.Container components = null;



		public ImportForm()

		{

			//

			// Windows 窗体设计器支持所必需的

			//

			InitializeComponent();



			//

			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码

			//

		}



		/// <summary>

		/// 清理所有正在使用的资源。

		/// </summary>

		protected override void Dispose( bool disposing )

		{

			if( disposing )

			{

				if (components != null) 

				{

					components.Dispose();

				}

			}

			base.Dispose( disposing );

		}







		#region Windows 窗体设计器生成的代码

		/// <summary>

		/// 设计器支持所需的方法 - 不要使用代码编辑器修改

		/// 此方法的内容。

		/// </summary>

		private void InitializeComponent()

		{

			this.Namelabel = new System.Windows.Forms.Label();

			this.ImportprogressBar = new System.Windows.Forms.ProgressBar();

			this.Importbutton = new System.Windows.Forms.Button();

			this.SuspendLayout();

			// 

			// Namelabel

			// 

			this.Namelabel.Location = new System.Drawing.Point(16, 40);

			this.Namelabel.Name = "Namelabel";

			this.Namelabel.Size = new System.Drawing.Size(152, 16);

			this.Namelabel.TabIndex = 0;

			// 

			// ImportprogressBar

			// 

			this.ImportprogressBar.Location = new System.Drawing.Point(24, 72);

			this.ImportprogressBar.Maximum = 14;

			this.ImportprogressBar.Name = "ImportprogressBar";

			this.ImportprogressBar.Size = new System.Drawing.Size(320, 23);

			this.ImportprogressBar.Step = 1;

			this.ImportprogressBar.TabIndex = 1;

			this.ImportprogressBar.Click += new System.EventHandler(this.ImportprogressBar_Click);

			// 

			// Importbutton

			// 

			this.Importbutton.Location = new System.Drawing.Point(128, 128);

			this.Importbutton.Name = "Importbutton";

			this.Importbutton.Size = new System.Drawing.Size(112, 32);

			this.Importbutton.TabIndex = 2;

			this.Importbutton.Text = "数据转换";

			this.Importbutton.Click += new System.EventHandler(this.Importbutton_Click);

			// 

			// ImportForm

			// 

			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);

			this.ClientSize = new System.Drawing.Size(368, 181);

			this.Controls.Add(this.Importbutton);

			this.Controls.Add(this.ImportprogressBar);

			this.Controls.Add(this.Namelabel);

			this.MaximizeBox = false;

			this.MinimizeBox = false;

			this.Name = "ImportForm";

			this.Text = "数据转换";

			this.ResumeLayout(false);



		}

		#endregion



		/// <summary>

		/// 应用程序的主入口点。

		/// </summary>

		[STAThread]

		static void Main() 

		{

			Application.Run(new ImportForm());

		}



		private void Importbutton_Click(object sender, System.EventArgs e)

		{

			string strCon = @"server=zhangqiang/zq;Integrated Security=true;database=derrickDBlq1;Persist Security Info=False;Integrated Security=SSPI;";

			SqlConnection MyCon = new SqlConnection(strCon);

			MyCon.Open();

//			SqlTransaction st = MyCon.BeginTransaction();

			try

			{

				ImportprogressBar.Value = 1;

				Namelabel.Text = " 出库历史记录表";



				string strSQL = @"INSERT INTO 出库历史记录表" + 

					"(totalId, 钻具名称, 规格, 标签号, 钢印号, 生产厂家, 钢级, 级别, 壁厚, 长度, 公接头外径, " +

					"公接头内径, 公接头长度, 母接头外径, 母接头长度, 螺纹型式, 累计使用时间, 累计进尺, " +

					"井队, 井号, 区块, 出库时间, 总数)" +

					"SELECT totalId, 钻具名称, 规格, 标签号, 钢印号, 生产厂家, 钢级, 级别, 壁厚, 长度, 公接头外径, " +

					"公接头内径, 公接头长度, 母接头外径, 母接头长度, 螺纹型式, 累计使用时间, 累计进尺, " +

					"井队, 井号, 区块, 出库时间, 总数 " +

					"FROM 出库历史记录表1";

				SqlCommand MyCommand = new SqlCommand(strSQL, MyCon);

				MyCommand.ExecuteNonQuery();



				strSQL = @"DELETE FROM 出库历史记录表1";

				MyCommand.CommandText = strSQL;

				MyCommand.ExecuteNonQuery();



				MessageBox.Show("转换完成", "提示信息");

				ImportprogressBar.Value = 0;

			}

			catch (Exception ex)

			{

				

				ImportprogressBar.Value = 0;

				MessageBox.Show(ex.Message);

			}

			finally

			{

				// 使用完毕,关闭数据库

				MyCon.Close();				

			}

		}



		private void ImportprogressBar_Click(object sender, System.EventArgs e)

		{

		

		}

	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值