ExecuteNonQuery()上的错误;

Max*_*yne 2 t-sql asp.net ado.net c#-4.0

我收到以下错误 ExecuteNonQuery()

"String or binary data would be truncated. The statement has been terminated."
Run Code Online (Sandbox Code Playgroud)

问题是要发送的变量大于DB中的变量.我使用以下代码:

      protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //GridViewRow row = GridView1.SelectedRow;
        GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
        var Username = (Label)row.FindControl("Label3");
        var Password = (Label)row.FindControl("Label4");
        var Email = (Label)row.FindControl("Label5");
       // var ID_Inscricao = ((Label)row.FindControl("Label1")).Text;
        var ID_Inscricao = ((Label)row.FindControl("Label1")).Text;


        SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["FormacaoConnectionString"].ToString());
        SqlCommand sqlComm = new SqlCommand();


        sqlComm = sqlConn.CreateCommand();
        sqlComm.Parameters.Add("@Username", SqlDbType.Text);
        sqlComm.Parameters.Add("@Password", SqlDbType.Text);
        sqlComm.Parameters.Add("@Email", SqlDbType.Text);
        sqlComm.Parameters.Add("@ID_Inscricao", SqlDbType.Int);

        sqlComm.Parameters["@Username"].Value = Convert.ToString(Username);
        sqlComm.Parameters["@Password"].Value = Convert.ToString(Password);
        sqlComm.Parameters["@Email"].Value = Convert.ToString(Email);
        sqlComm.Parameters["@ID_Inscricao"].Value = Convert.ToInt32(ID_Inscricao);

        string sql = "INSERT INTO Utilizadores (Username, Password, Email, ID_Inscricao) VALUES (@Username, @Password, @Email, @ID_Inscricao)";
        sqlComm.CommandText = sql;
        sqlConn.Open();
        sqlComm.ExecuteNonQuery();
        sqlConn.Close();
    }
Run Code Online (Sandbox Code Playgroud)

Ron*_*erg 6

当您尝试将某些内容插入到该列太长的列中时会发生这种情况.

例如,当您有一个列VARCHAR(10)并尝试插入该值时"ABCDEFGHIJKLMNOP".这将导致数据被截断并产生错误.

我不知道它在你的情况下是哪一列,但它必须是Username,Password或者Email.