用C#制作一个登陆界面,求教??
用C#制作的登录界面如何连接到数据库进行账号,密码的认证??????? --------------------编程问答-------------------- 汗! 你新手? 还是不回C#?新建一个页面 拖几个控件,再在CS文件写操作,连接数据库方法不就好了? --------------------编程问答-------------------- 你先上网找个例子看看吧 --------------------编程问答-------------------- 如果你的DLL给其他NET平台上的托管代码用,就如二楼的那样写就行了。如果你要给其他非托管代码调用,只能写成COM组件 --------------------编程问答-------------------- 楼主,这个问题问有点泛啊,你应该问得精细一点. --------------------编程问答-------------------- 你先先看看C#的基础,研究下ADO.NET --------------------编程问答-------------------- 晕。先看看C#基础知识 --------------------编程问答-------------------- 要看你是winfrom,还是web页面,都需要跟数据库打交道。
总体思路就是从界面上的用户名+密码,作为数据库的查询条件,如果在数据库中找到相应记录,说明用户名+密码正确,就可以登录了。如果没有找到相应记录,就给出提示,不让登录就行了! --------------------编程问答-------------------- 先去看看书,ado。net方面的。 --------------------编程问答-------------------- 基础,帮顶 --------------------编程问答-------------------- 彻底晕倒,刚学的不,刚学的也不至于问这样的问题出来啊! --------------------编程问答-------------------- 楼主你好,我这里有一个简单链接数据库的例子,有登陆界面,有验证,需要的话请和我联系,QQ:97212287 --------------------编程问答-------------------- 刚学么?登陆界面和其他界面没什么区别的啊 --------------------编程问答-------------------- using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Data.SqlClient;
using System.Text;
using System.Windows.Forms;
namespace ERP_FZ
{
public partial class Form1 : Form
{
DataClass.Class1 ID_Name = new ERP_FZ.DataClass.Class1();
public Form1()
{
InitializeComponent();
}
SqlConnection conn;
private void button3_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim () == "" || textBox2.Text.Trim () == "")
{
MessageBox.Show("绋娣彐桢犱稿负绌猴?);
textBox1.Text = "";
textBox2.Text = "";
textBox1.Focus();
}
else
{
try
{
if (conn.State == ConnectionState.Open) //澶姝姣濡驽兼版?
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select count(*) from data001 where id='" + textBox1.Text.Trim() + "'and pw='" + textBox2.Text.Trim() + "' ";
cmd.CommandType = CommandType.Text;
int i = Convert.ToInt32(cmd.ExecuteScalar());
if (i > 0)
{
DataClass.Class1.ID_Name = textBox1.Text.Trim();
conn.Close();
this.Hide();
Form2 frm2 = new Form2();
frm2.Show();
}
else
{
textBox1.Text = "";
textBox2.Text = "";
textBox1.Focus();
MessageBox.Show("绋娣彐桢犳璇艰殒拌惧ワ?);
}
}
else
{
MessageBox.Show("缃缁楫棰瀵艰存版鸿挎ヤ告甯革?);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
textBox1.Focus();
conn = new SqlConnection("server=168.1.1.242;database=ERP2010;uid=sa;pwd=123456");
conn.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
textBox2.Focus();
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
button3.Focus();
}
private void button2_Click(object sender, EventArgs e)
{
conn.Close();
conn.Dispose();
Application.Exit();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
conn.Close();
Application.Exit();
}
}
} --------------------编程问答-------------------- 建议网上搜搜例子(就在csdn找就好),这样的例子很多的,里面有很详细的方法 --------------------编程问答-------------------- bang ding xia... --------------------编程问答-------------------- 晕死。。。 拖几个控件。然后写SQL语句进行判断就OK了 --------------------编程问答--------------------
严重抢分 --------------------编程问答-------------------- using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Data.SqlClient;
using System.Text;
using System.Windows.Forms;
namespace ERP_FZ
{
public partial class Form1 : Form
{
DataClass.Class1 ID_Name = new ERP_FZ.DataClass.Class1();
public Form1()
{
InitializeComponent();
}
SqlConnection conn;
private void button3_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim () == "" || textBox2.Text.Trim () == "")
{
MessageBox.Show("绋娣彐桢犱稿负绌猴?);
textBox1.Text = "";
textBox2.Text = "";
textBox1.Focus();
}
else
{
try
{
if (conn.State == ConnectionState.Open) //澶姝姣濡驽兼版?
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select count(*) from data001 where id='" + textBox1.Text.Trim() + "'and pw='" + textBox2.Text.Trim() + "' ";
cmd.CommandType = CommandType.Text;
int i = Convert.ToInt32(cmd.ExecuteScalar());
if (i > 0)
{
DataClass.Class1.ID_Name = textBox1.Text.Trim();
conn.Close();
this.Hide();
Form2 frm2 = new Form2();
frm2.Show();
}
else
{
textBox1.Text = "";
textBox2.Text = "";
textBox1.Focus();
MessageBox.Show("绋娣彐桢犳璇艰殒拌惧ワ?);
}
}
else
{
MessageBox.Show("缃缁楫棰瀵艰存版鸿挎ヤ告甯革?);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
textBox1.Focus();
conn = new SqlConnection("server=168.1.1.242;database=ERP2010;uid=sa;pwd=123456");
conn.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
textBox2.Focus();
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
button3.Focus();
}
private void button2_Click(object sender, EventArgs e)
{
conn.Close();
conn.Dispose();
Application.Exit();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
conn.Close();
Application.Exit();
}
}
}
这可以 --------------------编程问答-------------------- MessageBox.Show("绋娣彐桢犳璇艰殒拌惧ワ?);---这是哪国文字啊? --------------------编程问答-------------------- MessageBox.Show("文字说明 ","提示名称"?);---这是哪国文字啊?
中国的文字 不过是乱码的中国的文字 --------------------编程问答-------------------- 额.......... --------------------编程问答-------------------- 看MSSQL和ado.net吧。。。。。。 --------------------编程问答-------------------- 呵呵,楼主网上一大堆的例子,真要是啥都不会网上找个现成移植一下就行了,当初我刚学的时候就是这样的,复制粘贴总会吧!如果外行的话,那就没办法了! --------------------编程问答-------------------- 看看下面这个例子里的登录界面是你所需要的吗?
http://download.csdn.net/source/2418601
--------------------编程问答-------------------- 你在数据库中要建立一个帐号 专门作为程序连接数据库用的
帐号密码 都尽量复杂
用户登录窗体输入的帐号密码 只是作为数据库里面 用户帐号表里面的数据 --------------------编程问答-------------------- 控件 + 存储过程。
搞定。 --------------------编程问答-------------------- 悲哀呀、 --------------------编程问答-------------------- 楼主 这个问题很简单的 我想你应该是新手...慢慢来 好好练练...相信你 --------------------编程问答-------------------- 刚开始都是这样的没事 --------------------编程问答-------------------- 楼主新手哈,比我还新呐,加油哇,希望不久的将来我们都能成为一个合格的程序员!~~ --------------------编程问答-------------------- 我也是新手。也不懂c#
但我也照样调试的好好的。一懂的人帮我写了注册程序,最简单的那种。只有帐户名和密码。然后我在本地调试成功了,你要学习下不。我发给你。 --------------------编程问答-------------------- 有这么贴子,怎么不见LZ出来回复. --------------------编程问答-------------------- 这个是比较简单 ,多上网查查 --------------------编程问答-------------------- 连接数据库,找个留言板实例看看 --------------------编程问答-------------------- 楼主,如果是web的在51aspx.com里找点例子看看。什么都是不会到会的,没事,有钻研精神就好。嘿嘿。加油 --------------------编程问答-------------------- 运行结果怎么是这样,求解释,先谢谢了.
找不到类型或命名空间名称“DataClass”(是否缺少 using 指令或程序集引用?) --------------------编程问答-------------------- o ,努力了 --------------------编程问答-------------------- 确实挺简单 --------------------编程问答-------------------- --------------------编程问答-------------------- +1 --------------------编程问答-------------------- using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Login
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
//退出按钮消息提示,是否确认退出
private void button2_Click(object sender, EventArgs e)
{
DialogResult result;
result = MessageBox.Show("你确定要退出?", "退出提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
result = MessageBox.Show("你真的确定要退出?", "退出提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
this.Close();
}
}
}
//判断用户是否输入用户名密码,选择用户类型
private bool ValidateInput()
{
if (txtLoinId.Text.Trim() == "")
{
MessageBox.Show("请输入用户名");
txtLoinId.Focus();
return false;
}
else if (txtPassword.Text.Trim() == "")
{
MessageBox.Show("请输入密码");
txtPassword.Focus();
return false;
}
else if (cboType.Text.Trim() == "")
{
MessageBox.Show("请选择用户类型");
cboType.Focus();
return false;
}
else
{
return true;
}
}
//验证用户是否有效,--------------分方法做各个功能----------
//private bool ValidateUser()
//{
// //如果监控没有异常,则ValidateUser()的值为true;如果监控出现异常,那么ValidateUser()的值为false
// bool isfind = false; //默认未找到用户
// try//只是执行一个监控的任务
// {
// //打开连接,链接数据库,好接收从数据库中传来的信息
// DBHelper.connection.Open();
// //SQL语句。将我们要对数据库操作的语句赋给一个字符串
// string sql = "";
// switch (cboType.Text)
// {
// case "学员":
// sql = string.Format("select count(*) from student where loginid ='{0}'and loginpwd ='{1}' ", txtLoinId.Text, txtPassword.Text);
// break;
// case "管理员":
// sql = string.Format("select count(*) from admin where loginid='{0}' and loginpwd ='{1}'", txtLoinId.Text, txtPassword.Text);
// break;
// default:
// sql = string.Format("select count(*) from teacher where loginid='{0}' and loginpwd ='{1}'", txtLoinId.Text, txtPassword.Text);
// break;
// }
// //命令执行。使用connection的对象和sql字符串
// SqlCommand cmd = new SqlCommand(sql, DBHelper.connection);
// //执行操作
// int count = Convert.ToInt32(cmd.ExecuteScalar());
// if (count > 0)
// {
// isfind = true;
// string ff = cboType.Text + "数据库中有" + count + "条数据";
// MessageBox.Show(ff, "显示提示");
// }
// else
// {
// //MessageBox.Show("用户名和密码不存在,请重新输入!", "输入提示",MessageBoxButtons .OKCancel ,MessageBoxIcon.Information );
// // return false ;
// //消息框的返回值是一个dialogresult类型
// DialogResult result;
// result = MessageBox.Show("用户名和密码不存在,请重新输入!", "输入提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
// if (result == DialogResult.OK)
// {
// result = MessageBox.Show("你选择了确定按钮,确定要离开吗!", "输入提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
// if (result == DialogResult.OK)
// {
// DialogResult result1 = MessageBox.Show("你真的要离开吗?考虑一下吧", "");
// if (result == DialogResult.OK)
// {
// MessageBox.Show("滚吧!");
// }
// else
// {
// MessageBox.Show("你觉悟了!还不算晚!");
// }
// }
// else
// {
// MessageBox.Show("真好,你觉悟了!");
// }
// }
// else
// {
// MessageBox.Show("你选择了取消按钮", "输入提示");
// }
// }
// }
// catch (Exception ex)
// {
// //提示错误
// MessageBox.Show(ex.Message);
// }
// finally
// {
// //关闭连接
// DBHelper.connection.Close();
// }
// return isfind;
//}
private void type()
{
switch (cboType.Text)
{
case "管理员":
AdminForm Admin = new AdminForm();
Admin.Show();
this.Visible = false;
break;
case "教员":
jiayuan jy = new jiayuan();
jy.Show();
break;
case "学员":
TianJiaXY xy = new TianJiaXY();
xy.Show();
break;
default:
MessageBox.Show("请检查输入类型", "输入提示");
break;
}
}
private void button1_Click(object sender, EventArgs e)
{
if (ValidateInput())
{
//先保存,后打开窗体
//if (ValidateUser())
//{
//将输入的用户名保存到静态变量中
Userhelper.loginId = txtLoinId.Text;
//将选择的登录类型保存到静态变量中
Userhelper.loginType = cboType.Text;
type();
//}
//else
//{
// return;
//}
}
}
}
}
--------------------编程问答--------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using FileOpeat.DataSetLoginTableAdapters;
namespace FileOpeat
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.skinEngine1.SkinFile = "MSN.ssk";
}
private void button2_Click(object sender, EventArgs e)
{
this.txtname.Clear();
this.txtpwd.Clear();
}
/// <summary>
/// 主要进行登录操作;
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
if(txtname.Text==""||txtpwd.Text==""){
MessageBox.Show("请输入数据 ","提示",MessageBoxButtons.OK,MessageBoxIcon.Question);
return;
}
tb_userinfoTableAdapter userinfo = new tb_userinfoTableAdapter();
FileOpeat.DataSetLogin.tb_userinfoDataTable usertalbe=userinfo.GetDataByGetName(txtname.Text.Trim());
if(usertalbe.Count<=0){
MessageBox.Show("用户名错误","错误提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
///用户名存在,进行下面的操作;获取行
for (int i = 0; i < usertalbe.Rows.Count;i++ )
{/// 获取行数
FileOpeat.DataSetLogin.tb_userinfoRow rowname = usertalbe[i];
string username = rowname.username;
string userpwd = rowname.userpwd;
if(username!=txtname.Text||userpwd!=txtpwd.Text){
MessageBox.Show("输入的数据有误","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
///数据正确,登录成功!
MainShow mainshow = new MainShow();
this.Hide();
mainshow.Show();
}
}
private void txtname_TextChanged(object sender, EventArgs e)
{
}
}
}
补充:.NET技术 , C#