| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 628 人关注过本帖
标题:新手求教在c#窗体程序设计完成,运行程序出现当前上下文中不存在文件名txtU ...
只看楼主 加入收藏
EBC1
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-4-16
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
新手求教在c#窗体程序设计完成,运行程序出现当前上下文中不存在文件名txtUserName
private void button1_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text.Trim() == "" || txtUserPassword.Text.Trim == "")
            {
                MessageBox.Show("用户名或密码不能为空!");

                txtUserName.Focus();
                return;
            
            
            }

            string connString = @"Data Source=windows-PC;Initial Catalog=AddressList;Integrated Security=True";
            string sqlStr = string.Format("select count(*) from [User] where UserName='{0}' and Password='{1}'",txtUserName.Text.Trim,txtUserPassword.Text.Trim());
            using (SqlConnection conn = new SqlConnection(connString))
            {
                SqlCommand amd = new SqlCommand(sqlStr, conn);
                conn.Open();
                int  n=Convert.ToInt32(cmd.ExecuteScalar());
                if (n == 1)
                {
                    MessageBox.Show("登录成功!");


                }
                else
                {
                    MessageBox.Show("用户名或密码错误!","错误");
                    txtUserName.Text = "";
                    txtUserPassword.Text = "";
                    txtUserName.Focus();
               
               
                 }
搜索更多相关主题的帖子: 运行程序 程序设计 private 用户名 return 
2015-04-16 09:51
Maick
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:32
帖 子:251
专家分:1314
注 册:2012-9-21
收藏
得分:7 
if (txtUserName.Text.Trim() == "" || txtUserPassword.Text.Trim == "")
            {
                MessageBox.Show("用户名或密码不能为空!");
                //注释掉吧.提示就没有这个名叫:txtUserName的textbox
               // txtUserName.Focus();
                return;
            
            
            }
2015-04-16 10:11
hellation
Rank: 2
等 级:论坛游民
帖 子:38
专家分:56
注 册:2015-4-11
收藏
得分:7 
肯定是你最初的时候名命名的,然后删掉了,可是这样应该提示(下面有红线啊),何况这行代码没有什么意义   删了吧
2015-04-18 22:04
sun282430724
Rank: 2
等 级:论坛游民
威 望:1
帖 子:30
专家分:94
注 册:2015-4-20
收藏
得分:7 
新手路过.楼主加油!!
2015-04-20 13:35
快速回复:新手求教在c#窗体程序设计完成,运行程序出现当前上下文中不存在文件名 ...
数据加载中...
 
   



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

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