输入的字符串格式不正确? [英] Input string was not in a correct format ????

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

问题描述

大家好,

执行该代码时出现问题:

Hi every body,

I have problem when execute that code:

using (SqlConnection con = new SqlConnection(connectionString))
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Loging";
            cmd.Parameters.AddWithValue("@UserName", username);
            cmd.Parameters.AddWithValue("@PassWord", password);
            con.Open();
            int x =Convert.ToInt32(cmd.ExecuteScalar());
            isAuthenticated = x == 1;
            
        }



它给我以下消息:
输入的字符串格式不正确.


它在这部分代码上标记:
int x = Convert.ToInt32(cmd.ExecuteScalar());


?????????



It give me this message:
Input string was not in a correct format.


It marks on this part of code :
int x =Convert.ToInt32(cmd.ExecuteScalar());


?????????

推荐答案

我愿意是您的cmd返回的内容与int类型不兼容. br/>
存储的proc的返回类型是什么?创建一个变量,首先将结果分配给该变量.然后设置一个断点,看看返回了什么.

干杯.
I''d be willing to be that your cmd is returning something that is not compatible with the int type.

What is the return type on the stored proc? Create a variable, assign the result to that first. Then set a breakpoint and see what''s returned.

Cheers.


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

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