ArrySore 2017-01-18 10:19 采纳率: 0%
浏览 1053
已结题

C#WinFrom 出现异常:将截断字符串和二进制数据

我数据库的数据类型和长度都是很符合的。
图片说明

这是我的代码:try
{
string phone = this.texone.Text.Trim();
string pwd = this.txtpwd.Text.Trim();
string pwd2 = this.textpwd2.Text.Trim();
string name = this.texname.Text.Trim();
string sex = "";
if (this.ckboy.Checked == true)
{
sex = "0";
}
else
{
sex = "1";
}
string Adress = this.txtAdress.Text.Trim();
string Idcard = this.txtIdCard.Text.Trim();

            if (pwd.Equals(pwd2))
            {

            }
            else
            {
                MessageBox.Show("两次密码不相等");
                this.txtpwd.Focus();
            }
            con = new SqlConnection(conString);
            con.Open();
            string sql = string.Format("INSERT [User] VALUES('{0}','{1}','{2}','{3}','{4}','{5}')", phone, pwd, name, sex, Idcard, Adress);
            SqlCommand com = new SqlCommand(sql, con);
            int isRet = com.ExecuteNonQuery();
            if (isRet>= 1)
            {
                MessageBox.Show("注册成功!");
            }
            else
            {
                MessageBox.Show("注册失败!");
            }
        }
        catch (Exception)
        {
            MessageBox.Show("出现异常!");
            throw;
        }
        con.Close();
        this.Close();
    }

    private void button2_Click(object sender, EventArgs e)
    {
        MessageBox.Show("确定要退出吗?");
        this.Close();
    }
  • 写回答

5条回答 默认 最新

  • Kolamu 2017-01-18 11:13
    关注

    是不是输入了中文?代码没什么异常

    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元