我是V#初学者,做的c/s的登录界面,希望哪位好心人能帮忙纠正哈该代码的错误,谢谢

ApplePane 2011-09-20 04:49:52
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace InformationApplication1
{
public partial class Form1Login : Form
{
public Form1Login()
{
InitializeComponent();
}

private void label1_Click(object sender, EventArgs e)
{

}

private void Form1Login_Load(object sender, EventArgs e)
{

}

private void btnLogin_Click(object sender, EventArgs e)
{
try
{
if (txtUserName.Text.Trim() == "")
{
MessageBox.Show("用户名不能为空!", "错误");
txtUserName.Focus();
return;
}
else if (txtUserPassword.Text.Trim() == "")
{
MessageBox.Show("密码不能为空!", "错误");
txtUserName.Focus();
return;
}
this.Text = "正在验证。。。。";
this.Cursor=System.Windows.Forms .Cursor.waitCursor;
String sqlStr="select userPassword from Table_Login where userName=" + txtUserName.Text.Trim()+"" ;
DataSet ds=new DataSet();
CDataBase.conn.ConnectionString=CDataBase .connStr;
CDataBase .conn.Open();
SqlDataAdapter adapter=new SqlDataAdapter(sqlStr .conn);
adapter.Fill(ds);
if(ds.Tables[0].Rows.Count==0)
{
MessageBox.Show("用户名错误,请重新输入!","错误");
this.Cursor=System.Windows.Forms.Cursor.Arrow;
this.Text="登录";
txtUserName.Text="";
txtUserPassword.Text="";
txtUserName.Focus();
}
else
if(ds.Tables[0].Rows[0].ItemArray[0].ToString().Trim()==txtUserPassword.Text.Trim())
{
FrmMain ob_FrmMain=new FrmMain();
CPublic.userInfo[0]=txtUserName.Text.Trim();
CPublic.userInfo[1]=txtUserPassword.Text.Trim();
CPublic.userInfo[2]=ds.Tables[0].Rows[0].ItemArray[1].ToString().Trim();
CPublic.userInfo[3]=ds.Tables[0].Rows[0].ItemArray[2].ToString().Trim();
this.Cursor=System.Windows.Forms.Cursor.Arrow;
this.Text="登录";
ob_FrmMain.show();
this.Hide();

}
else
{
MessageBox.Show("密码错误,请重新输入!","错误");
this.Cursor=System.Windows.Forms.Cursor.Arrow;
this.Text="登录";
txtUserPassword.Text="";
txtUserPassword.Focus();
}

}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"登录异常");
this.Cursor=System.Windows.Forms.Cursor.Arrow;
this.Text="登录";
txtUserName.Text="";
txtUserPassword.Text="";
txtUserName.Focus();


}
finally
{
CDataBase.conn.Close();
}
}

private void btnCancel_Click(object sender, EventArgs e)
{

}

private void btnCancel_Click_1(object sender, EventArgs e)
{
Application.Exit();
}

private void txtUserPassword_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
btnLogin_Click(sender, e);
}
}

private void Form1Login_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}

}
}

...全文
59 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
Please copy Error information.
pywepe 2011-09-20
  • 打赏
  • 举报
回复
what is v#
bios8086 2011-09-20
  • 打赏
  • 举报
回复
V#是什么
cjh200102 2011-09-20
  • 打赏
  • 举报
回复
看标题我也有点晕。

V#
xfxlylove 2011-09-20
  • 打赏
  • 举报
回复
问题出在那?
  • 打赏
  • 举报
回复
[code=C#]
String sqlStr="select userPassword from Table_Login where userName=" + txtUserName.Text.Trim()+"" ;
--->
String sqlStr="select userPassword from Table_Login where userName='" + txtUserName.Text.Trim()+"'" ;//存在SQL注入
[/Code]
lw8776 2011-09-20
  • 打赏
  • 举报
回复
楼主问题描述不清楚。。。
lei1988 2011-09-20
  • 打赏
  • 举报
回复
吓我一跳,我以为微软又出了个V#了。

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧