关于登录界面完了如何弹出主界面的问题?
主窗体的代码如下: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;
namespace frmMain
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
}
}
登录窗体的代码如下:
SqlConnection conn;//声明数据库连接对象
conn = new SqlConnection("Server=(local);User Id=sa;Pwd=;Database=energy statistics");
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
SqlCommand cmd = new SqlCommand("select count(*) from tb_Admin where AdminUserName='" + txtLoginName.Text + "' and AdminUserPwd='" + txtLoginPwd.Text + "'", conn);
int i=Convert.ToInt32(cmd.ExecuteScalar());
if(i>0)
{
frmMain.main=new frmMain();
//main.adminnanme=txtLoginName.Text;
//main.admintime=DataTime.Now.ToshortDataString();
main.show();
this.Hide();
}
为何连接不下,请高人指点??????????????
[解决办法]
应该是密码为空的原因,
sa设置一个密码试试
[解决办法]
把你的SqlCommand cmd = new SqlCommand("select count(*) from tb_Admin where AdminUserName='" + txtLoginName.Text + "' and AdminUserPwd='" + txtLoginPwd.Text + "'", conn);
改成这个试试。
string sql = string.Format("select count(*) from FamilyU where UserName='{0}'and UserPass='{1}'", txtName.Text.Trim(), txtPass.Text.Trim());
[解决办法]
主窗体
switch(new LoginForm(){ShowInDasktop=false}.ShowDialog())
{
DialogResult.Yes:
// 继续操作
break;
Default:
// 结束操作
}
登录窗体LoginForm
如果登录成功
DialogResult=DialogResult.Yes;
点击取消
DialogResult=DialogResult.No;