Int32的值太大或太小...... [英] Value was either too large or too small for an Int32...

查看:451
本文介绍了Int32的值太大或太小......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  string  insertquery =   INSERT INTO regtab VALUES(' + txtname.Text +  ',' + txtemail.Text +  ',' + txtpassword.Text +  ',' + txtaddress.Text +  ', + Convert.ToInt32(txtcontact.Text)+  ; 

CreateConnection();
SqlCommand cmd = new SqlCommand(insertquery,con);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (i > 0
{
lblmsg.Text = 成功创建员工档案 ;


}





这是数据库值:

id (int)

名称(varchar50)

电子邮件(varchar50)

密码(varchar50)

地址(varchar50 )

联系人(bigint)

解决方案

首先使用参数化查询。转换前使用 Int64.TryParse方法 [ ^ ]并使用out参数读取值。

string insertquery = "INSERT INTO regtab VALUES('" + txtname.Text + "','" + txtemail.Text + "','" + txtpassword.Text +"','" + txtaddress.Text + "'," + Convert.ToInt32(txtcontact.Text) + ")";
       
        CreateConnection();
        SqlCommand cmd = new SqlCommand(insertquery, con);
        con.Open();
        int i =cmd.ExecuteNonQuery();
        con.Close();
        if (i > 0)
        {
            lblmsg.Text = "Create Employee Profile Successfully";


        }



This is database Values:
id(int)
name(varchar50)
email(varchar50)
password(varchar50)
address(varchar50)
contact(bigint)

解决方案

First use parameterized query. And before conversion use Int64.TryParse Method[^] and use out parameter to read the value.


这篇关于Int32的值太大或太小......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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