我无法理解这个错误可以请你帮忙找到这个答案 [英] I can't understand this error could please you help find this answer

查看:88
本文介绍了我无法理解这个错误可以请你帮忙找到这个答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要花时间来完成这个程序。请求如何找到这个解决方案



SQL异常发生

故障排除异常:System.Data.SqlClient.SqlException



无法将值NULL插入列'UserID',表'UserRegitrationDB。 dbo.tblUser;列不允许空值。 INSERT失败。



我尝试过:



 命名空间 LoginForm 
{
public < span class =code-keyword> partial class Form1:Form
{
public Form1()
{
InitializeComponent();


private void button1_Click( object sender,EventArgs e)
{
if (txtUserName.Text == || txtConfirmPassword.Text ==
MessageBox.Show( 请填写必填字段 );
else if (txtPassword.Text!= txtConfirmPassword.Text)
MessageBox。显示( 密码不匹配);
else
{
使用(SqlConnection sqlcon = new SqlConnection(connectionstring))
{
sqlcon.Open();
SqlCommand sqlcmd = new SqlCommand( UserAdd ,sqlcon);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.AddWithValue( @ FirstName,txtFirstName.Text.Trim() );
sqlcmd.Parameters.AddWithValue( @ LastName,txtLastName.Text.Trim() );
sqlcmd.Parameters.AddWithValue( @ Contact,txtContact.Text.Trim() );
sqlcmd.Parameters.AddWithValue( @ Address,txtAddress.Text.Trim() );
sqlcmd.Parameters.AddWithValue( @ UserName,txtUserName.Text.Trim() );

sqlcmd.ExecuteNonQuery();
MessageBox.Show( 注册成功);
clear();
}
}
}
void clear()
{
txtFirstName.Text = txtLastName.Text = txtContact.Text = txtAddress.Text = txtUserName.Text = txtPassword.Text = txtConfirmPassword.Text = ;
}
}
}

解决方案

我们不知道该代码的用途是什么,更不用说你没想到的那样,或者你没做过。我们无法测试它,因为我们无法访问您的存储过程,更不用说您的实际数据了。



所以,它取决于您。

在函数的第一行放置一个断点,然后通过调试器运行代码。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。


对不起,但我们不能为你做到这一点 - 时间让你学习一种新的(非常非常有用的)技能:调试!



但不要这样做!切勿以明文形式存储密码 - 这是一个主要的安全风险。有关如何在此处执行此操作的信息:密码存储:如何做到这一点。 [ ^ ]

It's a matter of time for me to work this program.could pleas how to find this solution

SQL Exception Occurred
Troubleshooting Exceptions: System.Data.SqlClient.SqlException

Cannot insert the value NULL into column 'UserID', table 'UserRegitrationDB.dbo.tblUser'; column does not allow nulls. INSERT fails.

What I have tried:

namespace LoginForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();


        private void button1_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text == "" || txtConfirmPassword.Text == "")
                MessageBox.Show("Please Fill Mandatory Field");
            else if (txtPassword.Text != txtConfirmPassword.Text)
                MessageBox.Show("Password do not Match");
            else
            {
                using (SqlConnection sqlcon = new SqlConnection(connectionstring))
                {
                    sqlcon.Open();
                    SqlCommand sqlcmd = new SqlCommand("UserAdd",sqlcon);
                    sqlcmd.CommandType = CommandType.StoredProcedure;
                    sqlcmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text.Trim());
                    sqlcmd.Parameters.AddWithValue("@LastName", txtLastName.Text.Trim());
                    sqlcmd.Parameters.AddWithValue("@Contact", txtContact.Text.Trim());
                    sqlcmd.Parameters.AddWithValue("@Address", txtAddress.Text.Trim());
                    sqlcmd.Parameters.AddWithValue("@UserName", txtUserName.Text.Trim());
                  
                    sqlcmd.ExecuteNonQuery();
                    MessageBox.Show("Registration is Successfull");
                    clear();
                }
            }
        }
        void clear()
        {
            txtFirstName.Text = txtLastName.Text = txtContact.Text = txtAddress.Text = txtUserName.Text = txtPassword.Text = txtConfirmPassword.Text = "";
        }
    }
}

解决方案

We have no idea what that code is meant to do, much less what it does that you didn't expect, or not do that you did. And we can't test it, because we have no access to your Stored procedure, much less your actual data.

So, its going to be up to you.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!

But don't do it like that! Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]


这篇关于我无法理解这个错误可以请你帮忙找到这个答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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