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

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace nnn
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox2;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private nnn.DataSet1 dataSet11;
/// <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.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.dataSet11 = new nnn.DataSet1();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 48);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 24);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(48, 176);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 32);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(184, 176);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 32);
this.button2.TabIndex = 2;
this.button2.Text = "button2";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(144, 48);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(64, 21);
this.textBox1.TabIndex = 3;
this.textBox1.Text = "textBox1";
//
// label2
//
this.label2.Location = new System.Drawing.Point(40, 104);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(48, 24);
this.label2.TabIndex = 4;
this.label2.Text = "label2";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(144, 104);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(72, 21);
this.textBox2.TabIndex = 5;
this.textBox2.Text = "textBox2";
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=ZJ;packet size=4096;integrated security=SSPI;initial catalog=admin" +
";persist security info=False";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "admin", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("name", "name"),
new System.Data.Common.DataColumnMapping("password", "password")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT name, password FROM admin";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO admin(name, password) VALUES (@name, @password); SELECT name, passwor" +
"d FROM admin";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@name", System.Data.SqlDbType.VarChar, 10, "name"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@password", System.Data.SqlDbType.VarChar, 10, "password"));
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
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)
{
// 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 admin where name='"+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);
}
}
}
}



运行时出现错误请大家帮帮我看看!

搜索更多相关主题的帖子: System using Forms private Windows 
2006-03-20 12:11
louti
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2006-3-16
收藏
得分:0 
好长啊,等吃了饭再看吧
2006-03-25 11:29
ytyt654
Rank: 2
等 级:新手上路
威 望:4
帖 子:195
专家分:0
注 册:2006-2-13
收藏
得分:0 
// this.sqlSelectCommand1.ExecuteNonQuery();
SqlDataReader dr=this.sqlSelectCommand1.ExecuteReader();

问题可能出在这里

2006-03-25 12:52
月夜枫华
Rank: 4
等 级:贵宾
威 望:12
帖 子:437
专家分:42
注 册:2006-1-2
收藏
得分:0 
this.sqlConnection1.ConnectionString = "workstation id=DQL;packet size=4096;user id=sa;data source=DQL;persist security i" +
"nfo=False;initial catalog=addresslist";
怎么没看到Password属性?

2006-03-25 14:41
快速回复:用户登录的问题
数据加载中...
 
   



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

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