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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示