⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form2.cs

📁 一个SQLServer数据库的字段内容批量替换程序。 在实际生产中使用过
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace SQL_Replace
{
	/// <summary>
	/// Form2 的摘要说明。
	/// </summary>
	public class Form2 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox txtResult;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private DataTable myDataTable;
		private string strSearchText;
		private string strIp;
		private string strName;
		private string strUserName;
		private string strUserPasswd;

		public Form2()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

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

		public Form2(string strSText, string strDBIp, string strDBName, string strDBUserName, string strDBUserPasswd)
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			strSearchText = strSText;
			strIp = strDBIp;
			strName = strDBName;
			strUserName = strDBUserName;
			strUserPasswd = strDBUserPasswd;

			//
			// 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.txtResult = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// txtResult
			// 
			this.txtResult.Location = new System.Drawing.Point(0, 0);
			this.txtResult.Multiline = true;
			this.txtResult.Name = "txtResult";
			this.txtResult.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.txtResult.Size = new System.Drawing.Size(592, 376);
			this.txtResult.TabIndex = 0;
			this.txtResult.Text = "";
			// 
			// Form2
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(592, 373);
			this.Controls.Add(this.txtResult);
			this.Name = "Form2";
			this.Text = "Form2";
			this.Load += new System.EventHandler(this.Form2_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void Form2_Load(object sender, System.EventArgs e)
		{
			string strConnParm;
			string strSQL;
			int nNum = 0;
			string strFuncName = "";

			strConnParm = "data source=" + strIp + 
				";initial catalog=" + strName + 
				";user id=" + strUserName + 
				";Password=" + strUserPasswd + 
				";persist security info=False;packet size=4096;Connect Timeout=15";

			strSQL = "select dataid, databody, dataname from datasetting where databody like '%" + 
				strSearchText + "%'";

			try
			{
				SqlConnection cn = new SqlConnection(strConnParm);
				cn.Open();

				SqlDataAdapter catDA = new SqlDataAdapter(strSQL, cn);       

				DataSet catDS = new DataSet();
				catDA.Fill(catDS, "datasetting");   

				myDataTable = catDS.Tables["datasetting"];

				cn.Close();

				strFuncName = "函数名:\r\n";
				for(int nI = 0; nI < myDataTable.Rows.Count; nI ++)
				{
					string strdataBody = myDataTable.Rows[nI]["databody"].ToString();
					if (strdataBody.IndexOf(strSearchText) != -1)
					{
						strFuncName += myDataTable.Rows[nI]["dataname"].ToString() + "\r\n";
						nNum ++;
					}
				}

				cn.Close();
			}
			catch(Exception ex)
			{
				throw ex;
			}

			if (nNum == 0)
			{
				this.txtResult.Text = "没有匹配的函数";
			}
			else
			{
				this.txtResult.Text = this.txtResult.Text.Insert(0, "总共有" + nNum.ToString() + "个函数匹配!\r\n\r\n") + strFuncName;
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -