| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 676 人关注过本帖
标题:有关登录窗体的问题
取消只看楼主 加入收藏
蘑菇
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2005-10-13
收藏
 问题点数:0 回复次数:1 
有关登录窗体的问题

这段代码是论坛一位版主写的登录程序,我下载了程序并且可以运行成功,但是把全部代码复制粘贴到新的平台却无法运行,请问我到底少了哪一步操作?
全部代码如下:


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace 登陆窗体
{
/// <summary>
/// Form2 的摘要说明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
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.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private 登陆窗体.DataSet1 dataSet11;
private System.Data.SqlClient.SqlCommand sqlSelectCommand2;
private System.Data.SqlClient.SqlConnection sqlConnection2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form2()
{
//
// 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.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.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand2 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection2 = new System.Data.SqlClient.SqlConnection();
this.SuspendLayout();
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Location = new System.Drawing.Point(8, 96);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 24);
this.button1.TabIndex = 0;
this.button1.Text = "登陆";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button2.Location = new System.Drawing.Point(104, 96);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(48, 24);
this.button2.TabIndex = 1;
this.button2.Text = "退出";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(40, 23);
this.label1.TabIndex = 2;
this.label1.Text = "姓名";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(40, 23);
this.label2.TabIndex = 3;
this.label2.Text = "密码";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(64, 16);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 4;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(64, 56);
this.textBox2.Name = "textBox2";
this.textBox2.PasswordChar = '*';
this.textBox2.TabIndex = 5;
this.textBox2.Text = "";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand2;
this.sqlDataAdapter1.RowUpdated += new System.Data.SqlClient.SqlRowUpdatedEventHandler(this.sqlDataAdapter1_RowUpdated);
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 姓名, 密码 FROM 登陆";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=\"NYIST-E0FC884B3\";packet size=4096;integrated security=SSPI;data s" +
"ource=\"NYIST-E0FC884B3\";persist security info=False;initial catalog=master";
//
// sqlSelectCommand2
//
this.sqlSelectCommand2.CommandText = "SELECT 姓名, 密码 FROM 登陆";
this.sqlSelectCommand2.Connection = this.sqlConnection2;
//
// sqlConnection2
//
this.sqlConnection2.ConnectionString = "workstation id=DQL;packet size=4096;user id=sa;data source=DQL;persist security i" +
"nfo=False;initial catalog=addresslist";
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(184, 142);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form2";
this.Text = "登陆窗体";
this.Load += new System.EventHandler(this.Form2_Load);
this.ResumeLayout(false);

}
#endregion

private void button1_Click(object sender, System.EventArgs e)
{
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=DQL;packet size=4096;user id=sa;data source=DQL;persist security i" +
"nfo=False;initial catalog=addresslist";
//
this.sqlSelectCommand1.CommandText="select * from Users where username='"+this.textBox1.Text.Trim()+"' and password='"+this.textBox2.Text.Trim()+"'";
this.sqlConnection1.Open();
this.sqlSelectCommand1.ExecuteNonQuery();
SqlDataReader dr=this.sqlSelectCommand1.ExecuteReader();
if(dr.Read())
{
MessageBox.Show("你已经登陆成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information,MessageBoxDefaultButton.Button1,MessageBoxOptions.DefaultDesktopOnly);
}
else
{
MessageBox.Show("姓名或者密码错误,请重新输入","错误",MessageBoxButtons.OK,MessageBoxIcon.Warning,MessageBoxDefaultButton.Button1,MessageBoxOptions.DefaultDesktopOnly);
}
}

private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}

private void Form2_Load(object sender, System.EventArgs e)
{

}

private void sqlDataAdapter1_RowUpdated(object sender, System.Data.SqlClient.SqlRowUpdatedEventArgs e)
{

}
}
}

搜索更多相关主题的帖子: 窗体 登录 
2005-12-26 22:42
蘑菇
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2005-10-13
收藏
得分:0 
问题解决了,原来是因为DataSet没有配置好
2005-12-26 22:57
快速回复:有关登录窗体的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017422 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved