输入字符串的心情不正确 [英] input string was not in correct mood

查看:79
本文介绍了输入字符串的心情不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i我正在制作一个登录页面并且它正在工作但是一旦我打开第一次然后我收到一条消息输入字符串不是在CRRECT FORMAT中

请检查并指导我在哪里错了







 < span class =code-keyword> private   void  button4_Click( object  sender,EventArgs e )
{
Form1 fr = new Form1();
fr.Refresh();
尝试
{
con = new SqlConnection( Data Source = .; Initial Catalog = DSIIDC2; Integrated Security = True);
cmd = new SqlCommand( select *从login登录,其中username =' + txtusername.Text + '和password =' + txtpassword.Text + '和role ='admin01',con);
// cmd = new SqlCommand(select username ='+ txtusername.Text +',password ='+ txtpassword.Text +'来自登录,其中role ='admin01');
SqlDataAdapter da = new SqlDataAdapter(cmd );
DataTable datatab = new DataTable();
da.Fill(datatab);
if admin == txtusername.Text&& dsiidc == txtpassword.Text&& admin01 == admin01
{
// Session [userone] = TextBox1.Text;

frm2.Show();


}
else if ((< span class =code-string> admin == txtusername.Text&& admin == txtpassword.Text&& admin02 == admin02))
{

ad.Show();
da.Dispose();

}
else
{
txtpassword.Text = ;
txtpassword.Text = ;


}

}

catch (例外情况)
{
MessageBox.Show( 请输入用户名和密码);
}


}

解决方案

如果您调试代码,你会看到哪行代码导致错误。然后你会看到字符串的问题。但是,我没有在你发布的代码中看到任何会再次引起错误的内容,请注意错误告诉你它发生的位置。



那么你也想改变你的代码来使用参数。



例如:

 cmd =  new  SqlCommand(  select * from login where username = @userName和密码= @密码和角色='admin01',con); 
cmd.Parameters.AddWithValue( @ userName,txtusername.Text);
cmd.Parameters.AddWithValue( @ password,txtpassword.Text);


hi
i am making a login page and it is working but once i open first time then i am getting a message " INPUT STRING WAS NOT IN CRRECT FORMAT"
PLEASE check and guide me where i am wrong



private void button4_Click(object sender, EventArgs e)
{
    Form1 fr = new Form1();
    fr.Refresh();
    try
    {
        con = new SqlConnection("Data Source=.;Initial Catalog=DSIIDC2;Integrated Security=True");
        cmd = new SqlCommand("select * from login where username='" + txtusername.Text + "' and password='" + txtpassword.Text + "' and role='admin01'", con);
       // cmd = new SqlCommand("select username='" + txtusername.Text + "', password='" + txtpassword.Text + "' from login where role='admin01'");
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable datatab = new DataTable();
        da.Fill(datatab);
        if ("admin" == txtusername.Text && "dsiidc" == txtpassword.Text && "admin01" == "admin01")
        {
            //Session["userone"] = TextBox1.Text;

            frm2.Show();


        }
        else if (("admin" == txtusername.Text && "admin" == txtpassword.Text && "admin02" == "admin02"))
        {

            ad.Show();
            da.Dispose();

        }
        else
        {
            txtpassword.Text = "";
            txtpassword.Text = "";


        }

    }

    catch (Exception ex)
    {
        MessageBox.Show("Please Enter User name and password");
    }


}

解决方案

If you debug the code you'll see which line of code is causing the error. Then you'll see what the problem is with the string. However, I don't see anything in the code you have posted that would cause that error so again, pay attention to where the error tells you it is happening.

Then you'll also want to change your code to use parameters.

For example:

 cmd = new SqlCommand("select * from login where username=@userName and password=@password and role='admin01'", con);
cmd.Parameters.AddWithValue("@userName", txtusername.Text);
cmd.Parameters.AddWithValue("@password", txtpassword.Text);


这篇关于输入字符串的心情不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆