📄 dataform1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;
namespace WindowsApplication14
{
/// <summary>
/// DataForm1 的摘要说明。
/// </summary>
public class DataForm1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.SaveFileDialog saveFileDialog2;
public System.Windows.Forms.Label label1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.ServiceProcess.ServiceController serviceController1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Data.SqlClient.SqlCommand sqlCommand1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button daorudatabas;
private System.Windows.Forms.Button daoruEXCEL;
private System.Windows.Forms.Button jiazai;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.ComboBox comboBox2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.GroupBox groupBox2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public DataForm1()
{
//
// 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()
{
System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
this.button1 = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.daorudatabas = new System.Windows.Forms.Button();
this.saveFileDialog2 = new System.Windows.Forms.SaveFileDialog();
this.label1 = new System.Windows.Forms.Label();
this.daoruEXCEL = new System.Windows.Forms.Button();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.jiazai = new System.Windows.Forms.Button();
this.serviceController1 = new System.ServiceProcess.ServiceController();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlCommand1 = new System.Data.SqlClient.SqlCommand();
this.label2 = new System.Windows.Forms.Label();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.button2 = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.button3 = new System.Windows.Forms.Button();
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.button4 = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(840, 88);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(112, 24);
this.button1.TabIndex = 4;
this.button1.Text = "使用说明";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(136, 88);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 5;
this.comboBox1.ValueMember = ((string)(configurationAppSettings.GetValue("comboBox1.ValueMember", typeof(string))));
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// daorudatabas
//
this.daorudatabas.Location = new System.Drawing.Point(592, 88);
this.daorudatabas.Name = "daorudatabas";
this.daorudatabas.Size = new System.Drawing.Size(112, 23);
this.daorudatabas.TabIndex = 6;
this.daorudatabas.Text = "从磁盘导入数库";
this.daorudatabas.Click += new System.EventHandler(this.button2_Click);
//
// saveFileDialog2
//
this.saveFileDialog2.Filter = "EXCEL(*.xls)|*.xls|(文本文件)|*.txt";
//
// label1
//
this.label1.Location = new System.Drawing.Point(112, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(456, 24);
this.label1.TabIndex = 7;
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// daoruEXCEL
//
this.daoruEXCEL.Location = new System.Drawing.Point(440, 88);
this.daoruEXCEL.Name = "daoruEXCEL";
this.daoruEXCEL.Size = new System.Drawing.Size(120, 24);
this.daoruEXCEL.TabIndex = 9;
this.daoruEXCEL.Text = "导入到磁盘文件";
this.daoruEXCEL.Click += new System.EventHandler(this.button3_Click);
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 152);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.Size = new System.Drawing.Size(952, 400);
this.dataGrid1.TabIndex = 10;
this.dataGrid1.Navigate += new System.Windows.Forms.NavigateEventHandler(this.dataGrid1_Navigate);
//
// jiazai
//
this.jiazai.Location = new System.Drawing.Point(288, 88);
this.jiazai.Name = "jiazai";
this.jiazai.Size = new System.Drawing.Size(120, 24);
this.jiazai.TabIndex = 11;
this.jiazai.Text = "查询数据";
this.jiazai.Click += new System.EventHandler(this.button4_Click);
//
// serviceController1
//
this.serviceController1.MachineName = ((string)(configurationAppSettings.GetValue("serviceController1.MachineName", typeof(string))));
this.serviceController1.ServiceName = ((string)(configurationAppSettings.GetValue("serviceController1.ServiceName", typeof(string))));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=\"TEAMONEI-2CV21I\";packet size=4096;user id=sa;data source=\"TEAMONE" +
"I-2CV21I\";persist security info=False;initial catalog=tianwei";
//
// sqlCommand1
//
this.sqlCommand1.CommandText = ((string)(configurationAppSettings.GetValue("sqlCommand1.CommandText", typeof(string))));
this.sqlCommand1.Connection = this.sqlConnection1;
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 616);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(104, 24);
this.label2.TabIndex = 13;
this.label2.Text = "SQL语言执行脚本";
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(144, 608);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(560, 40);
this.richTextBox1.TabIndex = 14;
this.richTextBox1.Text = "";
this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged);
//
// button2
//
this.button2.Location = new System.Drawing.Point(752, 616);
this.button2.Name = "button2";
this.button2.TabIndex = 15;
this.button2.Text = "执行";
this.button2.Click += new System.EventHandler(this.button2_Click_1);
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 88);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(120, 16);
this.label3.TabIndex = 16;
this.label3.Text = "加载数据库表:";
//
// button3
//
this.button3.Location = new System.Drawing.Point(736, 88);
this.button3.Name = "button3";
this.button3.TabIndex = 17;
this.button3.Text = "退出(&X)";
this.button3.Click += new System.EventHandler(this.button3_Click_1);
//
// comboBox2
//
this.comboBox2.Location = new System.Drawing.Point(352, 24);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(121, 21);
this.comboBox2.TabIndex = 18;
this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged);
this.comboBox2.DataSourceChanged += new System.EventHandler(this.comboBox2_DataSourceChanged);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(136, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(120, 20);
this.textBox1.TabIndex = 19;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(592, 16);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(96, 20);
this.textBox2.TabIndex = 20;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(792, 16);
this.textBox3.Name = "textBox3";
this.textBox3.PasswordChar = '*';
this.textBox3.Size = new System.Drawing.Size(120, 20);
this.textBox3.TabIndex = 21;
this.textBox3.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(8, 24);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(120, 24);
this.label4.TabIndex = 22;
this.label4.Text = "输入服务器名:";
//
// label5
//
this.label5.Location = new System.Drawing.Point(280, 16);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(72, 24);
this.label5.TabIndex = 23;
this.label5.Text = "数据库:";
//
// label6
//
this.label6.Location = new System.Drawing.Point(496, 16);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(88, 24);
this.label6.TabIndex = 24;
this.label6.Text = "数据库用户:";
//
// label7
//
this.label7.Location = new System.Drawing.Point(728, 16);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(88, 24);
this.label7.TabIndex = 25;
this.label7.Text = "数据库密码:";
//
// button4
//
this.button4.Location = new System.Drawing.Point(592, 40);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(120, 24);
this.button4.TabIndex = 26;
this.button4.Text = "连接数据库";
this.button4.Click += new System.EventHandler(this.button4_Click_1);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.textBox2);
this.groupBox2.Controls.Add(this.label6);
this.groupBox2.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.textBox3);
this.groupBox2.Controls.Add(this.label7);
this.groupBox2.Controls.Add(this.button4);
this.groupBox2.Controls.Add(this.label1);
this.groupBox2.Location = new System.Drawing.Point(0, 8);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(928, 72);
this.groupBox2.TabIndex = 37;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "服务器连接设置";
//
// DataForm1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(968, 661);
this.Controls.Add(this.label4);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.comboBox2);
this.Controls.Add(this.label3);
this.Controls.Add(this.button2);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.jiazai);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.daoruEXCEL);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.daorudatabas);
this.Controls.Add(this.button1);
this.Controls.Add(this.button3);
this.Name = "DataForm1";
this.Text = "DataForm1";
this.Load += new System.EventHandler(this.DataForm1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
public string connstr1;
/*
public string dataconn()
{
Form1 frm=new Form1();
connstr1="server="+frm.str1+";Integrated Security=SSPI;database="+frm.str2+"";
}
*/
public void LoadDataSet()
{
try
{
string str1="select * from "+comboBox1.Text+"";
label1.Text="如果不输入数据!则默认连接为[.].[master]数据库账号SA,密码为空!";
// connstr1="server=teamonei-2cv21i;Integrated Security=SSPI;database=tianwei";
SqlConnection conn=new SqlConnection();
conn.ConnectionString="data source="+textBox1.Text+";initial catalog="+comboBox2.Text+";password="+textBox3.Text+" ;user id="+textBox2.Text+"";
//conn.ConnectionString=connstr1;
//"data source='.';initial catalog=tianwei;password='';user id=sa ;";
//SqlDataReader reader=null;
//conn=GetConnection();
conn.Open();
SqlCommand comm=new SqlCommand();
comm.Connection=conn;
comm.CommandText=str1;
//dataGrid1.DataSource=Dataset.
//reader=comm.ExecuteReader();
//conn.Close();
DataSet dataset=new DataSet ();
//string sql1="select * from tabtfd where 姓名='"+this.t b .Text +"'";
SqlDataAdapter a1=new SqlDataAdapter (str1,conn);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -