首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

用户登陆代码有关问题

2012-01-08 
用户登陆代码问题try{stringmyconn IntegratedSecuritySSPIUserIdsadatabasejindu2serverlocalho

用户登陆代码问题
try
                                {
                                        string     myconn= "Integrated   Security=SSPI;User   Id=sa;database=jindu2;server=localhost ";
                                        SqlConnection   myconnection=new   SqlConnection   (myconn);
                                        myconnection.Open();//打开数据库连接  
                                        string   usname= "select   *   from   userinfo   where   username= "+textBox1.Text   + "   and   password= "+textBox2.Text   + " ";
                                        SqlCommand   cmdd   =   new   SqlCommand(usname,   myconnection);
                                        SqlDataReader       myreader=cmdd.ExecuteReader();  
                                        if(myreader.Read   ())                                        
                                        {
                                                Form1   form1=new   Form1   ();
                                                form1.Show   ();
                                                this.Dispose   ();
                                        }
                                        else
                                                MessageBox.Show   ( "你输入的密码不正确,请重新输入 ");
                                        myreader.Close   ();
                                        myconnection.Close   ();
                                }


                       
                                catch(Exception       ex)
                                {
                                        MessageBox.Show   (ex.ToString());
                                }

输入用户名和密码总是提示列名无效,比如用户名li,密码123,则提示列名 'li '无效,列名 '123 '无效
这是什么错误呢,请高手指教

[解决办法]
少引号了!

string usname= "select * from userinfo where username= ' "+textBox1.Text + " ' and password= ' "+textBox2.Text + " ' ";

[解决办法]
string usname = "select * from userinfo where username = ' "+textBox1.Text + " ' and password = ' "+ textBox2.Text + " ' ";

为什么不用参数 or 存储过程?

热点排行