Visualizzazione dei risultati da 1 a 4 su 4

Discussione: Messaggio di errore

  1. #1

    Messaggio di errore

    Salve,
    sto cercando di imparare asp.net, e sto analizzando uno starterkit, qualcuno può darmi una indicazione su questo messaggio di errore?

    Messaggio di errore del parser: La classe base contiene il campo 'Email', il cui tipo (System.String) non è compatibile con quello del controllo (System.Web.UI.WebControls.TextBox).

    Di seguito il codice. Grazie



    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;

    namespace ASPNET.StarterKit.Commerce {

    //************************************************** *****
    //
    // CustomerDetails Class
    //
    // A simple data class that encapsulates details about
    // a particular customer inside the Commerce Customer
    // database.
    //
    //************************************************** *****

    public class CustomerDetails : System.Web.UI.Page
    {

    public String FullName;
    public String Email;
    public String Password;
    }

    //************************************************** *****
    //
    // CustomersDB Class
    //
    // Business/Data Logic Class that encapsulates all data
    // logic necessary to add/login/query customers within
    // the Commerce Customer database.
    //
    //************************************************** *****

    public class CustomersDB {

    //************************************************** *****
    //
    // CustomersDB.GetCustomerDetails() Method <a name="GetCustomerDetails"></a>
    //
    // The GetCustomerDetails method returns a CustomerDetails
    // struct that contains information about a specific
    // customer (name, email, password, etc).
    //
    // Other relevant sources:
    // + CustomerDetail Stored Procedure
    //
    //************************************************** *****

    public CustomerDetails GetCustomerDetails(String customerID)
    {

    // Create Instance of Connection and Command Object
    SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
    SqlCommand myCommand = new SqlCommand("CMRC_CustomerDetail", myConnection);

    // Mark the Command as a SPROC
    myCommand.CommandType = CommandType.StoredProcedure;

    // Add Parameters to SPROC
    SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int, 4);
    parameterCustomerID.Value = Int32.Parse(customerID);
    myCommand.Parameters.Add(parameterCustomerID);

    SqlParameter parameterFullName = new SqlParameter("@FullName", SqlDbType.NVarChar, 50);
    parameterFullName.Direction = ParameterDirection.Output;
    myCommand.Parameters.Add(parameterFullName);

    SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 50);
    parameterEmail.Direction = ParameterDirection.Output;
    myCommand.Parameters.Add(parameterEmail);

    SqlParameter parameterPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 50);
    parameterPassword.Direction = ParameterDirection.Output;
    myCommand.Parameters.Add(parameterPassword);

    myConnection.Open();
    myCommand.ExecuteNonQuery();
    myConnection.Close();

    // Create CustomerDetails Struct
    CustomerDetails myCustomerDetails = new CustomerDetails();

    // Populate Struct using Output Params from SPROC
    myCustomerDetails.FullName = (string)parameterFullName.Value;
    myCustomerDetails.Password = (string)parameterPassword.Value;
    myCustomerDetails.Email = (string)parameterEmail.Value;

    return myCustomerDetails;
    }

    //************************************************** *****
    //
    // CustomersDB.AddCustomer() Method <a name="AddCustomer"></a>
    //
    // The AddCustomer method inserts a new customer record
    // into the customers database. A unique "CustomerId"
    // key is then returned from the method. This can be
    // used later to place orders, track shopping carts,
    // etc within the ecommerce system.
    //
    // Other relevant sources:
    // + CustomerAdd Stored Procedure
    //
    //************************************************** *****

    public String AddCustomer(string fullName, string email, string password)
    {

    // Create Instance of Connection and Command Object
    SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
    SqlCommand myCommand = new SqlCommand("CMRC_CustomerAdd", myConnection);

    // Mark the Command as a SPROC
    myCommand.CommandType = CommandType.StoredProcedure;

    // Add Parameters to SPROC
    SqlParameter parameterFullName = new SqlParameter("@FullName", SqlDbType.NVarChar, 50);
    parameterFullName.Value = fullName;
    myCommand.Parameters.Add(parameterFullName);

    SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 50);
    parameterEmail.Value = email;
    myCommand.Parameters.Add(parameterEmail);

    SqlParameter parameterPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 50);
    parameterPassword.Value = password;
    myCommand.Parameters.Add(parameterPassword);

    SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int, 4);
    parameterCustomerID.Direction = ParameterDirection.Output;
    myCommand.Parameters.Add(parameterCustomerID);

    try {
    myConnection.Open();
    myCommand.ExecuteNonQuery();
    myConnection.Close();

    // Calculate the CustomerID using Output Param from SPROC
    int customerId = (int)parameterCustomerID.Value;

    return customerId.ToString();
    }
    catch {
    return String.Empty;
    }
    }

    //************************************************** *****
    //
    // CustomersDB.Login() Method <a name="Login"></a>
    //
    // The Login method validates a email/password pair
    // against credentials stored in the customers database.
    // If the email/password pair is valid, the method returns
    // the "CustomerId" number of the customer. Otherwise
    // it will throw an exception.
    //
    // Other relevant sources:
    // + CustomerLogin Stored Procedure
    //
    //************************************************** *****

    public String Login(string email, string password)
    {

    // Create Instance of Connection and Command Object
    SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
    SqlCommand myCommand = new SqlCommand("CMRC_CustomerLogin", myConnection);

    // Mark the Command as a SPROC
    myCommand.CommandType = CommandType.StoredProcedure;

    // Add Parameters to SPROC
    SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 50);
    parameterEmail.Value = email;
    myCommand.Parameters.Add(parameterEmail);

    SqlParameter parameterPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 50);
    parameterPassword.Value = password;
    myCommand.Parameters.Add(parameterPassword);

    SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int, 4);
    parameterCustomerID.Direction = ParameterDirection.Output;
    myCommand.Parameters.Add(parameterCustomerID);

    // Open the connection and execute the Command
    myConnection.Open();
    myCommand.ExecuteNonQuery();
    myConnection.Close();

    int customerId = (int)(parameterCustomerID.Value);

    if (customerId == 0) {
    return null;
    }
    else {
    return customerId.ToString();
    }
    }
    }
    }

  2. #2
    Utente di HTML.it
    Registrato dal
    Sep 2002
    Messaggi
    4,127
    qualke indicazione sulla riga e sull'errore, xkè sinceramente non credo ci sia nessuno ke si vuole leggere tutto quel codice

  3. #3
    Purtroppo il compilatore non mi restituisce indicazioni circa la posizione dell'errore, in definitiva ciò che io vorrei capire è la natura dell'errore dal punto di vista concettuale, ho postato il codice solo per completezza, mi rendo conto che è tropp lungo per analizzarlo.

    Grazie

  4. #4
    Utente di HTML.it
    Registrato dal
    Sep 2002
    Messaggi
    4,127
    cerca nel tuo codice questa riga
    parameterEmail.Value = email;
    e rimpiazzala con
    parameterEmail.Value = email.Text;

    dall'errore sembra ke email sia un textbox

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 © 2026 vBulletin Solutions, Inc. All rights reserved.