本帖最后由 hb1122 于 2011-04-09 10:21:39 编辑

解决方案 »

  1.   

            /// <summary>
            /// 根据字段类型,生成特定的条件语句
            /// </summary>
            /// <param name="ColumnName"></param>
            /// <param name="FindStr"></param>
            /// <param name="type"></param>
            /// <returns></returns>
            private String BuildFilStr(String ColumnName, String FindStr, String  type)
            { 
                switch  (type)
                {
                    #region 数字
                        //tinyint
                    case "48":
                        return " [" + ColumnName  + "] = " + FindStr ;                    
                        //smallint
                    case "52":
                        return " [" + ColumnName + "] = " + FindStr;    
                        //int
                    case  "56":
                        return " [" + ColumnName + "] = " + FindStr;    
                        //real
                    case "59":
                        return " [" + ColumnName + "] = " + FindStr;    
                        //float
                    case "62":
                        return " [" + ColumnName + "] = " + FindStr;                    
                        //decimal
                    case "106":
                        return " [" + ColumnName + "] = " + FindStr;    
                        //numeric
                    case "108":
                        return " [" + ColumnName + "] = " + FindStr;    
                        //bigint
                    case "127":
                        return " [" + ColumnName + "] = " + FindStr;
                    #endregion
                    #region 字符
                    //varchar
                    case "167":
                        return " [" + ColumnName + "] = '" + FindStr + "'"; 
                        //char
                    case "175":
                        return " [" + ColumnName + "] = '" + FindStr + "'"; 
                        //nvarchar
                    case "231":
                        return " [" + ColumnName + "] = '" + FindStr + "'"; 
                        //nchar
                    case "239":
                        return " [" + ColumnName + "] = '" + FindStr + "'";
                    #endregion
                    default :
                        return " [" + ColumnName + "] = '" + FindStr + "'";            }        }
            /// <summary>
            /// 查找表中是否
            /// </summary>
            /// <param name="Conn"></param>
            /// <param name="TableName"></param>
            /// <param name="FieldFil"></param>
            /// <returns></returns>
            private void FindValue(SqlConnection Conn, String TableName, String FieldFil)
            {
                try
                {
                   
                    using (SqlCommand FindCmd = new SqlCommand("select top 1 * from " + TableName + " where  " + FieldFil, Conn ))
                    {
                        using (SqlDataReader FindRead = FindCmd.ExecuteReader())
                        {
                            if (FindRead.Read())
                            {
                                DataRow newRow = TableDt.NewRow();
                                newRow["name"] = TableName;
                                TableDt.Rows.Add(newRow);
                            }
                        }
                    }            }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString()+ "\n tablename:" +  TableName + "\n fil:" + FieldFil  );
                }
                finally
                {
                    System.Threading.Thread.Sleep(50);
                }
            }        private String GetTypeFil(String Str)
            {
                try
                {
                    //转数字成功,则在文本和数字中找,不然只在文本中找
                    Decimal value = Decimal.Parse(Str);
                    return " 48, 52, 56,  59, 62,  106, 108, 127, 167, 175, 231, 231, 239";
                }
                catch
                {
                    //转数字失败,确定是文本
                    return " 167, 175, 231, 239  ";
                }        }        /*
             SQL中的系统字段表中的字段类型 xtype    类型
    34 image  
    35 text
    36 uniqueidentifier
    48 tinyint
    52 smallint
    56 int
    58 smalldatetime
    59 real
    60 money
    61 datetime
    62 float
    98 sql_variant
    99 ntext
    104 bit
    106 decimal
    108 numeric
    122 smallmoney
    127 bigint
    165 varbinary
    167 varchar
    173 binary
    175 char
    189 timestamp
    231 sysname
    231 nvarchar
    239 nchar  
       */  
        }
    }
      

  2.   

    namespace WorkBoardControl.FindDataBase
    {
        partial class FindFromDataBase
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.IContainer components = null;        /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }        #region Windows Form Designer generated code        /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.label1 = new System.Windows.Forms.Label();
                this.label2 = new System.Windows.Forms.Label();
                this.label3 = new System.Windows.Forms.Label();
                this.label4 = new System.Windows.Forms.Label();
                this.label6 = new System.Windows.Forms.Label();
                this.DataSourceName = new System.Windows.Forms.TextBox();
                this.Port = new System.Windows.Forms.TextBox();
                this.UserName = new System.Windows.Forms.TextBox();
                this.Pwd = new System.Windows.Forms.TextBox();
                this.DataBaseName = new System.Windows.Forms.TextBox();
                this.FieldName = new System.Windows.Forms.TextBox();
                this.ValueInfo = new System.Windows.Forms.TextBox();
                this.label5 = new System.Windows.Forms.Label();
                this.label7 = new System.Windows.Forms.Label();
                this.button1 = new System.Windows.Forms.Button();
                this.button2 = new System.Windows.Forms.Button();
                this.splitContainer1 = new System.Windows.Forms.SplitContainer();
                this.groupControl1 = new DevExpress.XtraEditors.GroupControl();
                this.FindTable = new System.Windows.Forms.DataGridView();
                this.groupControl2 = new DevExpress.XtraEditors.GroupControl();
                this.ShowInfo = new System.Windows.Forms.DataGridView();
                this.splitContainer2 = new System.Windows.Forms.SplitContainer();
                this.splitContainer1.Panel1.SuspendLayout();
                this.splitContainer1.Panel2.SuspendLayout();
                this.splitContainer1.SuspendLayout();
                ((System.ComponentModel.ISupportInitialize)(this.groupControl1)).BeginInit();
                this.groupControl1.SuspendLayout();
                ((System.ComponentModel.ISupportInitialize)(this.FindTable)).BeginInit();
                ((System.ComponentModel.ISupportInitialize)(this.groupControl2)).BeginInit();
                this.groupControl2.SuspendLayout();
                ((System.ComponentModel.ISupportInitialize)(this.ShowInfo)).BeginInit();
                this.splitContainer2.Panel1.SuspendLayout();
                this.splitContainer2.Panel2.SuspendLayout();
                this.splitContainer2.SuspendLayout();
                this.SuspendLayout();
                // 
                // label1
                // 
                this.label1.AutoSize = true;
                this.label1.Location = new System.Drawing.Point(12, 13);
                this.label1.Name = "label1";
                this.label1.Size = new System.Drawing.Size(41, 12);
                this.label1.TabIndex = 0;
                this.label1.Text = "数据源";
                // 
                // label2
                // 
                this.label2.AutoSize = true;
                this.label2.Location = new System.Drawing.Point(435, 13);
                this.label2.Name = "label2";
                this.label2.Size = new System.Drawing.Size(29, 12);
                this.label2.TabIndex = 1;
                this.label2.Text = "密码";
                // 
                // label3
                // 
                this.label3.AutoSize = true;
                this.label3.Location = new System.Drawing.Point(562, 13);
                this.label3.Name = "label3";
                this.label3.Size = new System.Drawing.Size(41, 12);
                this.label3.TabIndex = 2;
                this.label3.Text = "数据库";
                // 
                // label4
                // 
                this.label4.AutoSize = true;
                this.label4.Location = new System.Drawing.Point(242, 13);
                this.label4.Name = "label4";
                this.label4.Size = new System.Drawing.Size(29, 12);
                this.label4.TabIndex = 3;
                this.label4.Text = "端口";
                // 
                // label6
                // 
                this.label6.AutoSize = true;
                this.label6.Location = new System.Drawing.Point(323, 13);
                this.label6.Name = "label6";
                this.label6.Size = new System.Drawing.Size(41, 12);
                this.label6.TabIndex = 5;
                this.label6.Text = "用户名";
                // 
                // DataSourceName
                // 
                this.DataSourceName.ImeMode = System.Windows.Forms.ImeMode.Off;
                this.DataSourceName.Location = new System.Drawing.Point(59, 10);
                this.DataSourceName.Name = "DataSourceName";
                this.DataSourceName.Size = new System.Drawing.Size(177, 21);
                this.DataSourceName.TabIndex = 6;
                this.DataSourceName.Text = "192.168.100.230";
                // 
                // Port
                // 
                this.Port.Location = new System.Drawing.Point(277, 10);
                this.Port.Name = "Port";
                this.Port.Size = new System.Drawing.Size(40, 21);
                this.Port.TabIndex = 7;
                this.Port.Text = "1433";
                // 
                // UserName
                // 
                this.UserName.ImeMode = System.Windows.Forms.ImeMode.Off;
                this.UserName.Location = new System.Drawing.Point(370, 10);
                this.UserName.Name = "UserName";
                this.UserName.Size = new System.Drawing.Size(59, 21);
                this.UserName.TabIndex = 8;
                this.UserName.Text = "de";
                // 
                // Pwd
                // 
                this.Pwd.ImeMode = System.Windows.Forms.ImeMode.Off;
                this.Pwd.Location = new System.Drawing.Point(470, 10);
                this.Pwd.Name = "Pwd";
                this.Pwd.Size = new System.Drawing.Size(86, 21);
                this.Pwd.TabIndex = 9;
                this.Pwd.Text = "";
                // 
                // DataBaseName
                // 
                this.DataBaseName.ImeMode = System.Windows.Forms.ImeMode.Off;
                this.DataBaseName.Location = new System.Drawing.Point(609, 10);
                this.DataBaseName.Name = "DataBaseName";
                this.DataBaseName.Size = new System.Drawing.Size(137, 21);
                this.DataBaseName.TabIndex = 10;
                this.DataBaseName.Text = "AIS20081230134105";
                // 
                // FieldName
                // 
                this.FieldName.ImeMode = System.Windows.Forms.ImeMode.Off;
                this.FieldName.Location = new System.Drawing.Point(59, 47);
                this.FieldName.Name = "FieldName";
                this.FieldName.Size = new System.Drawing.Size(177, 21);
                this.FieldName.TabIndex = 11;
                // 
                // ValueInfo
                // 
                this.ValueInfo.ImeMode = System.Windows.Forms.ImeMode.Off;
                this.ValueInfo.Location = new System.Drawing.Point(59, 78);
                this.ValueInfo.Name = "ValueInfo";
                this.ValueInfo.Size = new System.Drawing.Size(177, 21);
                this.ValueInfo.TabIndex = 12;
                // 
                // label5
                // 
                this.label5.AutoSize = true;
                this.label5.Location = new System.Drawing.Point(12, 47);
                this.label5.Name = "label5";
                this.label5.Size = new System.Drawing.Size(41, 12);
                this.label5.TabIndex = 13;
                this.label5.Text = "字段名";
                // 
                // label7
                // 
                this.label7.AutoSize = true;
                this.label7.Location = new System.Drawing.Point(12, 78);
                this.label7.Name = "label7";
                this.label7.Size = new System.Drawing.Size(41, 12);
                this.label7.TabIndex = 14;
                this.label7.Text = "内  容";
                // 
                // button1
                // 
                this.button1.Location = new System.Drawing.Point(242, 45);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(92, 23);
                this.button1.TabIndex = 15;
                this.button1.Text = "找字段名";
                this.button1.UseVisualStyleBackColor = true;
                this.button1.Click += new System.EventHandler(this.button1_Click);
                
      

  3.   

    // 
                // button2
                // 
                this.button2.Location = new System.Drawing.Point(242, 76);
                this.button2.Name = "button2";
                this.button2.Size = new System.Drawing.Size(92, 23);
                this.button2.TabIndex = 16;
                this.button2.Text = "找数据内容";
                this.button2.UseVisualStyleBackColor = true;
                this.button2.Click += new System.EventHandler(this.button2_Click);
                // 
                // splitContainer1
                // 
                this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.splitContainer1.Location = new System.Drawing.Point(0, 0);
                this.splitContainer1.Name = "splitContainer1";
                // 
                // splitContainer1.Panel1
                // 
                this.splitContainer1.Panel1.Controls.Add(this.groupControl1);
                // 
                // splitContainer1.Panel2
                // 
                this.splitContainer1.Panel2.Controls.Add(this.groupControl2);
                this.splitContainer1.Size = new System.Drawing.Size(994, 433);
                this.splitContainer1.SplitterDistance = 240;
                this.splitContainer1.TabIndex = 17;
                // 
                // groupControl1
                // 
                this.groupControl1.Controls.Add(this.FindTable);
                this.groupControl1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.groupControl1.Location = new System.Drawing.Point(0, 0);
                this.groupControl1.Name = "groupControl1";
                this.groupControl1.Size = new System.Drawing.Size(240, 433);
                this.groupControl1.TabIndex = 0;
                this.groupControl1.Text = "数据库";
                // 
                // FindTable
                // 
                this.FindTable.AllowUserToAddRows = false;
                this.FindTable.AllowUserToDeleteRows = false;
                this.FindTable.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
                this.FindTable.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
                this.FindTable.Dock = System.Windows.Forms.DockStyle.Fill;
                this.FindTable.Location = new System.Drawing.Point(2, 21);
                this.FindTable.Name = "FindTable";
                this.FindTable.ReadOnly = true;
                this.FindTable.RowTemplate.Height = 23;
                this.FindTable.Size = new System.Drawing.Size(236, 410);
                this.FindTable.TabIndex = 0;
                // 
                // groupControl2
                // 
                this.groupControl2.Controls.Add(this.ShowInfo);
                this.groupControl2.Dock = System.Windows.Forms.DockStyle.Fill;
                this.groupControl2.Location = new System.Drawing.Point(0, 0);
                this.groupControl2.Name = "groupControl2";
                this.groupControl2.Size = new System.Drawing.Size(750, 433);
                this.groupControl2.TabIndex = 0;
                this.groupControl2.Text = "内容";
                // 
                // ShowInfo
                // 
                this.ShowInfo.AllowUserToAddRows = false;
                this.ShowInfo.AllowUserToDeleteRows = false;
                this.ShowInfo.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
                this.ShowInfo.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
                this.ShowInfo.Dock = System.Windows.Forms.DockStyle.Fill;
                this.ShowInfo.Location = new System.Drawing.Point(2, 21);
                this.ShowInfo.Name = "ShowInfo";
                this.ShowInfo.ReadOnly = true;
                this.ShowInfo.RowTemplate.Height = 23;
                this.ShowInfo.Size = new System.Drawing.Size(746, 410);
                this.ShowInfo.TabIndex = 0;
                // 
                // splitContainer2
                // 
                this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
                this.splitContainer2.Location = new System.Drawing.Point(0, 0);
                this.splitContainer2.Name = "splitContainer2";
                this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
                // 
                // splitContainer2.Panel1
                // 
                this.splitContainer2.Panel1.Controls.Add(this.label1);
                this.splitContainer2.Panel1.Controls.Add(this.button2);
                this.splitContainer2.Panel1.Controls.Add(this.label2);
                this.splitContainer2.Panel1.Controls.Add(this.button1);
                this.splitContainer2.Panel1.Controls.Add(this.label3);
                this.splitContainer2.Panel1.Controls.Add(this.label7);
                this.splitContainer2.Panel1.Controls.Add(this.label4);
                this.splitContainer2.Panel1.Controls.Add(this.label5);
                this.splitContainer2.Panel1.Controls.Add(this.label6);
                this.splitContainer2.Panel1.Controls.Add(this.ValueInfo);
                this.splitContainer2.Panel1.Controls.Add(this.DataSourceName);
                this.splitContainer2.Panel1.Controls.Add(this.FieldName);
                this.splitContainer2.Panel1.Controls.Add(this.Port);
                this.splitContainer2.Panel1.Controls.Add(this.DataBaseName);
                this.splitContainer2.Panel1.Controls.Add(this.UserName);
                this.splitContainer2.Panel1.Controls.Add(this.Pwd);
                this.splitContainer2.Panel1MinSize = 108;
                // 
                // splitContainer2.Panel2
                // 
                this.splitContainer2.Panel2.Controls.Add(this.splitContainer1);
                this.splitContainer2.Size = new System.Drawing.Size(994, 545);
                this.splitContainer2.SplitterDistance = 108;
                this.splitContainer2.TabIndex = 18;
                // 
                // FindFromDataBase
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(994, 545);
                this.Controls.Add(this.splitContainer2);
                this.Name = "FindFromDataBase";
                this.Text = "FindFromDataBase";
                this.splitContainer1.Panel1.ResumeLayout(false);
                this.splitContainer1.Panel2.ResumeLayout(false);
                this.splitContainer1.ResumeLayout(false);
                ((System.ComponentModel.ISupportInitialize)(this.groupControl1)).EndInit();
                this.groupControl1.ResumeLayout(false);
                ((System.ComponentModel.ISupportInitialize)(this.FindTable)).EndInit();
                ((System.ComponentModel.ISupportInitialize)(this.groupControl2)).EndInit();
                this.groupControl2.ResumeLayout(false);
                ((System.ComponentModel.ISupportInitialize)(this.ShowInfo)).EndInit();
                this.splitContainer2.Panel1.ResumeLayout(false);
                this.splitContainer2.Panel1.PerformLayout();
                this.splitContainer2.Panel2.ResumeLayout(false);
                this.splitContainer2.ResumeLayout(false);
                this.ResumeLayout(false);        }        #endregion        private System.Windows.Forms.Label label1;
            private System.Windows.Forms.Label label2;
            private System.Windows.Forms.Label label3;
            private System.Windows.Forms.Label label4;
            private System.Windows.Forms.Label label6;
            private System.Windows.Forms.TextBox DataSourceName;
            private System.Windows.Forms.TextBox Port;
            private System.Windows.Forms.TextBox UserName;
            private System.Windows.Forms.TextBox Pwd;
            private System.Windows.Forms.TextBox DataBaseName;
            private System.Windows.Forms.TextBox FieldName;
            private System.Windows.Forms.TextBox ValueInfo;
            private System.Windows.Forms.Label label5;
            private System.Windows.Forms.Label label7;
            private System.Windows.Forms.Button button1;
            private System.Windows.Forms.Button button2;
            private System.Windows.Forms.SplitContainer splitContainer1;
            private DevExpress.XtraEditors.GroupControl groupControl1;
            private DevExpress.XtraEditors.GroupControl groupControl2;
            private System.Windows.Forms.DataGridView FindTable;
            private System.Windows.Forms.DataGridView ShowInfo;
            private System.Windows.Forms.SplitContainer splitContainer2;
        }
    }