Link to home
Start Free TrialLog in
Avatar of hostopolis
hostopolisFlag for United States of America

asked on

Error: Cannot Find Column

I am getting an error that is confounding me. I'll show my code behind and the page code.

The error is: System.Data.EvaluateException: Cannot find column [P20070921033547].
"P20070921033547" represents a product number, and is not a column, so this message confuses me.
Avatar of p_davis
p_davis

if that is in a string for a select/update/insert make sure you are using ' instead of "
where does the error occur?
Avatar of hostopolis

ASKER

The error occurs here:


Line 22:       DataView dv = (DataView)SqlDataSource4.Select(DataSourceSelectArguments.Empty);
Line 23:       TextBox tb;
Line 24:       dv.RowFilter = "ProductNumber = " + ListBox3.SelectedValue;
Line 25:       if (dv.Count > 0)
Line 26:       {

In the code I meant to post originally:

Code behind:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class addproduct : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
  protected void ListBox3_SelectedIndexChanged(object sender, EventArgs e)
  {
    if (ListBox3.SelectedIndex > -1)
    {
      DataView dv = (DataView)SqlDataSource4.Select(DataSourceSelectArguments.Empty);
      TextBox tb;
      dv.RowFilter = "ProductNumber = " + ListBox3.SelectedValue;
      if (dv.Count > 0)
      {
        tb = (TextBox)FormView1.FindControl("ProductNumberTextBox");
        tb.Text = dv[0]["ProductNumber"].ToString();
        tb = (TextBox)FormView1.FindControl("ClientProductTextBox");
        tb.Text = dv[0]["ProductName"].ToString();
        tb = (TextBox)FormView1.FindControl("ClientProductDescTextBox");
        tb.Text = dv[0]["ProductDescription"].ToString();
        tb = (TextBox)FormView1.FindControl("ClientProductVersionTextBox");
        tb.Text = dv[0]["ProductVersion"].ToString();
        tb = (TextBox)FormView1.FindControl("ClientProductSerialNumberTextBox");
        tb.Text = dv[0]["ProductSerialNumber"].ToString();
        tb = (TextBox)FormView1.FindControl("ClientProductCategoryTextBox");
        tb.Text = dv[0]["ProductCategory"].ToString();
      }
    }
  }
}

Page Code:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="addproduct.aspx.cs" Inherits="addproduct" Title="ADS Intranet -- Add Client Products" Debug="true" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<script language="javascript" type="text/javascript">
function doIt(textBoxID)
    {
      var textBox = document.getElementById(textBoxID);
      textBox.value = document.getElementById("ctl00_ContentPlaceHolder1_ListBox1").options[document.getElementById("ctl00_ContentPlaceHolder1_ListBox1").selectedIndex].value;
    }
function doIt2(textBoxID)
    {
      var textBox = document.getElementById(textBoxID);
      textBox.value = document.getElementById("ctl00_ContentPlaceHolder1_ListBox2").options[document.getElementById("ctl00_ContentPlaceHolder1_ListBox2").selectedIndex].value;
    }
function doIt3(textBoxID)
    {
      var textBox = document.getElementById(textBoxID);
      textBox.value = document.getElementById("ctl00_ContentPlaceHolder1_ListBox3").options[document.getElementById("ctl00_ContentPlaceHolder1_ListBox3").selectedIndex].value;
    }
</script>

<table border="0">
  <tr>
    <td valign="top">
        <b>Clients</b><br />
        <asp:ListBox ID="ListBox1" runat="server" DataSourceID="SqlDataSource1"
            DataTextField="ClientCompany" DataValueField="ClientID" Height="300px" Width="120px" AutoPostBack="True" OnChange='doIt("ctl00$ContentPlaceHolder1$FormView1$ClientIDTextBox")'>
        </asp:ListBox>
    </td>
    <td valign="top" style="width: 3px">
        <b>Categories</b><br />
        <asp:ListBox ID="ListBox2" runat="server" Height="300px" Width="120px" DataSourceID="SqlDataSource3" DataTextField="CategoryName" DataValueField="CategoryID" AutoPostBack="True" OnChange='doIt2("ctl00$ContentPlaceHolder1$FormView1$ClientProductCategoryTextBox")'>
        </asp:ListBox></td>
    <td valign="top">
        <b>Products</b><br />
        <asp:ListBox ID="ListBox3" runat="server" Height="300px" Width="120px" DataSourceID="SqlDataSource4" DataTextField="ProductName" DataValueField="ProductNumber" AutoPostBack="True" OnChange='doIt3("ctl00$ContentPlaceHolder1$FormView1$ProductNumberTextBox")' OnSelectedIndexChanged="ListBox3_SelectedIndexChanged">
        </asp:ListBox>&nbsp;
    </td>
    <td valign="top" style="width: 270px">
        <asp:FormView ID="FormView1" runat="server" DataKeyNames="ClientProductID" DataSourceID="SqlDataSource2" DefaultMode="Insert">
            <InsertItemTemplate>
                <table>
  <tr>
    <td align="right">Client ID:</td>
    <td><asp:TextBox ID="ClientIDTextBox" runat="server" Text='<%# Bind("ClientID") %>'></asp:TextBox></td>
  </tr>
  <tr>
    <td align="right">Product:</td>
    <td><asp:TextBox ID="ClientProductTextBox" runat="server" Text='<%# Bind("ClientProduct") %>'></asp:TextBox></td>
  </tr>
  <tr>
      <td align="right">Product #:</td>
      <td><asp:TextBox ID="ProductNumberTextBox" runat="server" Text='<%# Bind("ProductNumber") %>'></asp:TextBox></td>
  </tr>
  <tr>
      <td align="right">Description:</td>
      <td><asp:TextBox ID="ClientProductDescTextBox" runat="server" Text='<%# Bind("ClientProductDesc") %>'></asp:TextBox></td>
  </tr>
  <tr>
      <td align="right">Version:</td>
      <td><asp:TextBox ID="ClientProductVersionTextBox" runat="server" Text='<%# Bind("ClientProductVersion") %>'></asp:TextBox></td>
  </tr>
  <tr>
      <td align="right">Serial #:</td>
      <td><asp:TextBox ID="ClientProductSerialNumberTextBox" runat="server" Text='<%# Bind("ClientProductSerialNumber") %>'></asp:TextBox></td>
  </tr>
  <tr>
      <td align="right">Category:</td>
      <td><asp:TextBox ID="ClientProductCategoryTextBox" runat="server" Text='<%# Bind("ClientProductCategory") %>'></asp:TextBox></td>
  </tr>
  <tr>
      <td align="right">Auth Code:</td>
      <td><asp:TextBox ID="ClientProductAuthCodeTextBox" runat="server" Text='<%# Bind("ClientProductAuthCode") %>'></asp:TextBox></td>
  </tr>
  <tr>
      <td align="right">Price:</td>
      <td><asp:TextBox ID="ClientProductPriceTextBox" runat="server" Text='<%# Bind("ClientProductPrice") %>'></asp:TextBox></td>
  </tr>
  <tr>
      <td align="right">Date:</td>
      <td><asp:TextBox ID="ClientProductPurchaseDateTextBox" runat="server" Text='<%# DateTime.Now.ToString("MM/dd/yyyy") %>' Enabled="False"></asp:TextBox></td>
  </tr>
  <tr>
      <td align="right">Sales Person:</td>
      <td><asp:TextBox ID="ClientProductSoldByTextBox" runat="server" Text='<%# Bind("ClientProductSoldBy") %>'></asp:TextBox></td>
  </tr>
  <tr>
      <td align="right" colspan="2"><asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert"></asp:Button></td>
  </tr>
</table>
            </InsertItemTemplate>
        </asp:FormView>
    </td>
  </tr>
</table>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClientDBConnectionString %>"
        ProviderName="<%$ ConnectionStrings:ClientDBConnectionString.ProviderName %>"
        SelectCommand="SELECT * FROM [Clients]"></asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ClientDBConnectionString %>"
        InsertCommand="INSERT INTO [ClientProducts] ([ClientID], [ClientProduct], [ProductNumber], [ClientProductDesc], [ClientProductVersion], [ClientProductSerialNumber], [ClientProductCategory], [ClientProductAuthCode], [ClientProductPrice], [ClientProductPurchaseDate], [ClientProductSoldBy]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
        ProviderName="<%$ ConnectionStrings:ClientDBConnectionString.ProviderName %>">
        <InsertParameters>
            <asp:Parameter Name="ClientID" Type="String" />
            <asp:Parameter Name="ClientProduct" Type="String" />
            <asp:Parameter Name="ProductNumber" Type="String" />
            <asp:Parameter Name="ClientProductDesc" Type="String" />
            <asp:Parameter Name="ClientProductVersion" Type="String" />
            <asp:Parameter Name="ClientProductSerialNumber" Type="String" />
            <asp:Parameter Name="ClientProductCategory" Type="String" />
            <asp:Parameter Name="ClientProductAuthCode" Type="String" />
            <asp:Parameter Name="ClientProductPrice" Type="String" />
            <asp:ControlParameter Name="ClientProductPurchaseDate" Type="String" ControlId="ctl00$ContentPlaceHolder1$FormView1$ClientProductPurchaseDateTextBox" PropertyName="Text"/>
            <asp:Parameter Name="ClientProductSoldBy" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ClientDBConnectionString %>"
        ProviderName="<%$ ConnectionStrings:ClientDBConnectionString.ProviderName %>"
        SelectCommand="SELECT * FROM [ProductCategories]"></asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:ClientDBConnectionString %>"
        ProviderName="<%$ ConnectionStrings:ClientDBConnectionString.ProviderName %>"
        SelectCommand="SELECT * FROM [Products] WHERE ([ProductCategory] = ?)">
        <SelectParameters>
            <asp:ControlParameter ControlID="ListBox2" Name="ProductCategory" PropertyName="SelectedValue"
                Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>

</asp:Content>
what if you put
on line 24
dv.RowFilter = "ProductNumber = " + ListBox3.SelectedValue.ToString();
Nope...didn't change anything.
which line specifically does the error occur
ASKER CERTIFIED SOLUTION
Avatar of CmdoProg2
CmdoProg2
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
doh!!  good catch CmdoProg2