using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// 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.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox2
//
this.textBox2.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
this.textBox2.Location = new System.Drawing.Point(208, 176);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(128, 21);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// button1
//
this.button1.BackColor = System.Drawing.SystemColors.Control;
this.button1.Font = new System.Drawing.Font("新宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.ForeColor = System.Drawing.SystemColors.InactiveCaption;
this.button1.Location = new System.Drawing.Point(128, 248);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "登陆(&L)";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.BackColor = System.Drawing.SystemColors.Control;
this.button2.Font = new System.Drawing.Font("新宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button2.ForeColor = System.Drawing.SystemColors.InactiveCaption;
this.button2.Location = new System.Drawing.Point(240, 248);
this.button2.Name = "button2";
this.button2.TabIndex = 3;
this.button2.Text = "退出(&E)";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label1
//
this.label1.BackColor = System.Drawing.SystemColors.Control;
this.label1.Font = new System.Drawing.Font("新宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.SystemColors.InactiveCaption;
this.label1.Location = new System.Drawing.Point(104, 96);
this.label1.Name = "label1";
this.label1.TabIndex = 4;
this.label1.Text = "用户名";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.BackColor = System.Drawing.SystemColors.Control;
this.label2.Font = new System.Drawing.Font("新宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.ForeColor = System.Drawing.SystemColors.InactiveCaption;
this.label2.Location = new System.Drawing.Point(104, 176);
this.label2.Name = "label2";
this.label2.TabIndex = 5;
this.label2.Text = "密码";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label3
//
this.label3.Location = new System.Drawing.Point(120, 24);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(216, 32);
this.label3.TabIndex = 6;
this.label3.Text = "公司名称";
//
// textBox1
//
this.textBox1.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
this.textBox1.Location = new System.Drawing.Point(208, 96);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(128, 21);
this.textBox1.TabIndex = 7;
this.textBox1.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(520, 349);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox2);
this.ForeColor = System.Drawing.Color.Black;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "Form1";
this.Text = "欢迎登陆";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
//验证信息
if(this.textBox1.Text==""||this.textBox2.Text=="")
{
MessageBox.Show("账号或密码不能为空!");
this.textBox1.Focus();
}
string sql="select * from Land where Admin_UserName='"+textBox1.Text.Trim()+"'and Admin_Passwd='"+textBox2.Text.Trim()+"'";
SqlConnection sqlcon = new SqlConnection("server =(Local);uid = sa; pwd =; database =TL01");
SqlCommand com=new SqlCommand(sql,sqlcon);
sqlcon.Open();
SqlDataReader sdr=com.ExecuteReader();
if(sdr.Read())
{
Form2 form2=new Form2();
form2.Show();
}
}
private void button2_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}
上面是登陆代码 实现的功能就是填入用户名和密码,然后直接转到Form2,我不知道哪里错了,点登陆,提示我(未处理的“System.Data.SqlClient.SqlException”类型的异常出现在 system.data.dll 中。
其他信息: 系统错误。) 调试中说"红字"的地方有问题~~~我实在搞不明白为什么??请斑竹和各位达人帮帮小弟忙,感激不尽~在线等~!!1