Hi Everyone,

I am currently practicing through the NorthWind Example in ASP.NET, when i debug i am greeted with the message "Could not find output table 'ViewCustomer'. Despite linking to the form in the try statement, am i missing something here? I am using a OleDb connection rather than SQL.

namespace Database
{
    public partial class AddCustomer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // N/A
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            OleDbConnection connect = new OleDbConnection();

            connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\ Programming\Northwind.mdb;Persist Security Info=False;";

            OleDbCommand command = new OleDbCommand();

            command.Connection = connect;
            command.CommandText = "INSERT INTO ViewCustomer (txtCustomerID, txtCompanyName, txtContactTitle, txtAddress, txtCity, txtRegion, txtPostalCode, txtCountry, txtPhone, txtFax) VALUES (@CustomerID, @CompanyName, @ContactTitle, @Address, @City, @Region, @PostalCode, @Country, @Phone, @Fax)";

            command.Parameters.AddWithValue("@CustomerID", this.txtCustomerID.Text);
            command.Parameters.AddWithValue("@CompanyName", this.txtCompanyName.Text);
            command.Parameters.AddWithValue("@ContactName", this.txtContactName.Text);
            command.Parameters.AddWithValue("@ContactTitle", this.txtContactTitle.Text);
            command.Parameters.AddWithValue("@Address", this.txtAddress.Text);
            command.Parameters.AddWithValue("@City", this.txtCity.Text);
            command.Parameters.AddWithValue("@Region", this.txtRegion.Text);
            command.Parameters.AddWithValue("@PostalCode", this.txtPostalCode.Text);
            command.Parameters.AddWithValue("@Country", this.txtCountry.Text);
            command.Parameters.AddWithValue("@Phone", this.txtPhone.Text);
            command.Parameters.AddWithValue("@Fax", this.txtFax.Text);

            try
            {   
                command.Connection.Open();
                int rowschanged = command.ExecuteNonQuery();
                if (rowschanged == 1)
                {
                    txtCustomerID.Text = "";
                    txtCompanyName.Text = "";
                    txtContactName.Text = "";
                    txtContactTitle.Text = "";
                    txtAddress.Text = "";
                    txtCity.Text = "";
                    txtRegion.Text = "";
                    txtPostalCode.Text = "";
                    txtCountry.Text = "";
                    txtPhone.Text = "";
                    txtFax.Text = "";
                    Response.Write("Done");
                    Response.Redirect("ViewCustomer.aspx");
                }
            }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
                 finally
            {
                command.Connection.Close();
            }
       }
        }
    }

You may want to have a look at your database and make sure that [ViewCustomer] is actually a data table and not a data view. I cannot imagine a database designer creating a table with a name that starts with the word view. That's just dangerous.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.