Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    3,072

    Errore in fase di insert - Column 'nome' cannot be null

    Da cosa può dipendere questo errore:


    Column 'nome' cannot be null


    Nel debug sembrano esserci i parametri corretti, in quanto

    return new MySqlParameter[]{
    utenteNomeParameter,
    utenteCognomeParameter,
    utenteEmailParameter,
    utentePasswordParameter
    };

    contengono i valori passati dal textbox

    cosa sbaglio??


    public virtual void Insert(WebUtente item)
    {
    if (item == null)
    {
    throw new ArgumentNullException("item", "Errore -> Elemento nullo");
    }

    try
    {
    SqlHelper.ExecuteNonQueryTxt(CommandType.Text,
    insertCommandText,
    GetParametersByEntity(item));

    }
    catch(Exception ex)
    {
    //Scrive l'errore nel LOG
    throw;
    }
    }



    protected virtual MySqlParameter[] GetParametersByEntity(WebUtente item)
    {
    MySqlParameter utenteNomeParameter = new MySqlParameter("@nome", MySqlDbType.VarChar, 150);
    utenteNomeParameter.Value = item.nome;
    MySqlParameter utenteCognomeParameter = new MySqlParameter("@cognome", MySqlDbType.VarChar, 150);
    utenteCognomeParameter.Value = item.cognome;
    MySqlParameter utenteEmailParameter = new MySqlParameter("@email", MySqlDbType.VarChar, 100);
    utenteEmailParameter.Value = item.mail;
    MySqlParameter utentePasswordParameter = new MySqlParameter("@password", MySqlDbType.VarChar, 60);
    utentePasswordParameter.Value = item.password;
    return new MySqlParameter[]{
    utenteNomeParameter,
    utenteCognomeParameter,
    utenteEmailParameter,
    utentePasswordParameter
    };
    }



    public static int ExecuteNonQueryTxt(CommandType commandType, string commandText, params MySqlParameter[] commandParameters)
    {
    if( connection == null ) throw new ArgumentNullException( "connection" );

    // Create a command and prepare it for execution
    MySqlCommand cmd = new MySqlCommand();
    MySqlConnection myconnection = new MySqlConnection(connection);
    bool mustCloseConnection = false;
    PrepareCommand(cmd, myconnection, (MySqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection);

    // Finally, execute the command
    int retval = cmd.ExecuteNonQuery();

    // Detach the MySqlParameters from the command object, so they can be used again
    cmd.Parameters.Clear();
    if( mustCloseConnection )
    myconnection.Close();
    return retval;
    }

  2. #2
    Column 'nome' cannot be null
    Non ho dato uno sguardo approfondito al codice(anche perché senza l'uso dei tag appositi...è quasi impossibile capirci qualcosa). Comunque prova a guardare nel Db, forse il campo nome è impostato in modo che non possa essere vuoto e nel recupero dei dati il valore di tale campo risulta vuoto...prova a far visualizzare la item.nome e vedi cosa ti esce.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.