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();
}
}
}
}