hostopolis
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.EvaluateExcept ion: Cannot find column [P20070921033547].
"P20070921033547" represents a product number, and is not a column, so this message confuses me.
The error is: System.Data.EvaluateExcept
"P20070921033547" represents a product number, and is not a column, so this message confuses me.
if that is in a string for a select/update/insert make sure you are using ' instead of "
where does the error occur?
ASKER
The error occurs here:
Line 22: DataView dv = (DataView)SqlDataSource4.S elect(Data SourceSele ctArgument s.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_SelectedIndexChan ged(object sender, EventArgs e)
{
if (ListBox3.SelectedIndex > -1)
{
DataView dv = (DataView)SqlDataSource4.S elect(Data SourceSele ctArgument s.Empty);
TextBox tb;
dv.RowFilter = "ProductNumber = " + ListBox3.SelectedValue;
if (dv.Count > 0)
{
tb = (TextBox)FormView1.FindCon trol("Prod uctNumberT extBox");
tb.Text = dv[0]["ProductNumber"].ToS tring();
tb = (TextBox)FormView1.FindCon trol("Clie ntProductT extBox");
tb.Text = dv[0]["ProductName"].ToStr ing();
tb = (TextBox)FormView1.FindCon trol("Clie ntProductD escTextBox ");
tb.Text = dv[0]["ProductDescription" ].ToString ();
tb = (TextBox)FormView1.FindCon trol("Clie ntProductV ersionText Box");
tb.Text = dv[0]["ProductVersion"].To String();
tb = (TextBox)FormView1.FindCon trol("Clie ntProductS erialNumbe rTextBox") ;
tb.Text = dv[0]["ProductSerialNumber "].ToStrin g();
tb = (TextBox)FormView1.FindCon trol("Clie ntProductC ategoryTex tBox");
tb.Text = dv[0]["ProductCategory"].T oString();
}
}
}
}
Page Code:
<%@ Page Language="C#" MasterPageFile="~/MasterPa ge.master" AutoEventWireup="true" CodeFile="addproduct.aspx. cs" Inherits="addproduct" Title="ADS Intranet -- Add Client Products" Debug="true" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Cont entPlaceHo lder1" Runat="Server">
<script language="javascript" type="text/javascript">
function doIt(textBoxID)
{
var textBox = document.getElementById(te xtBoxID);
textBox.value = document.getElementById("c tl00_Conte ntPlaceHol der1_ListB ox1").opti ons[docume nt.getElem entById("c tl00_Conte ntPlaceHol der1_ListB ox1").sele ctedIndex] .value;
}
function doIt2(textBoxID)
{
var textBox = document.getElementById(te xtBoxID);
textBox.value = document.getElementById("c tl00_Conte ntPlaceHol der1_ListB ox2").opti ons[docume nt.getElem entById("c tl00_Conte ntPlaceHol der1_ListB ox2").sele ctedIndex] .value;
}
function doIt3(textBoxID)
{
var textBox = document.getElementById(te xtBoxID);
textBox.value = document.getElementById("c tl00_Conte ntPlaceHol der1_ListB ox3").opti ons[docume nt.getElem entById("c tl00_Conte ntPlaceHol der1_ListB ox3").sele ctedIndex] .value;
}
</script>
<table border="0">
<tr>
<td valign="top">
<b>Clients</b><br />
<asp:ListBox ID="ListBox1" runat="server" DataSourceID="SqlDataSourc e1"
DataTextField="ClientCompa ny" DataValueField="ClientID" Height="300px" Width="120px" AutoPostBack="True" OnChange='doIt("ctl00$Cont entPlaceHo lder1$Form View1$Clie ntIDTextBo x")'>
</asp:ListBox>
</td>
<td valign="top" style="width: 3px">
<b>Categories</b><br />
<asp:ListBox ID="ListBox2" runat="server" Height="300px" Width="120px" DataSourceID="SqlDataSourc e3" DataTextField="CategoryNam e" DataValueField="CategoryID " AutoPostBack="True" OnChange='doIt2("ctl00$Con tentPlaceH older1$For mView1$Cli entProduct CategoryTe xtBox")'>
</asp:ListBox></td>
<td valign="top">
<b>Products</b><br />
<asp:ListBox ID="ListBox3" runat="server" Height="300px" Width="120px" DataSourceID="SqlDataSourc e4" DataTextField="ProductName " DataValueField="ProductNum ber" AutoPostBack="True" OnChange='doIt3("ctl00$Con tentPlaceH older1$For mView1$Pro ductNumber TextBox")' OnSelectedIndexChanged="Li stBox3_Sel ectedIndex Changed">
</asp:ListBox>
</td>
<td valign="top" style="width: 270px">
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ClientProduc tID" DataSourceID="SqlDataSourc e2" 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="ClientProductDescTextB ox" runat="server" Text='<%# Bind("ClientProductDesc") %>'></asp:TextBox></td>
</tr>
<tr>
<td align="right">Version:</td >
<td><asp:TextBox ID="ClientProductVersionTe xtBox" runat="server" Text='<%# Bind("ClientProductVersion ") %>'></asp:TextBox></td>
</tr>
<tr>
<td align="right">Serial #:</td>
<td><asp:TextBox ID="ClientProductSerialNum berTextBox " runat="server" Text='<%# Bind("ClientProductSerialN umber") %>'></asp:TextBox></td>
</tr>
<tr>
<td align="right">Category:</t d>
<td><asp:TextBox ID="ClientProductCategoryT extBox" runat="server" Text='<%# Bind("ClientProductCategor y") %>'></asp:TextBox></td>
</tr>
<tr>
<td align="right">Auth Code:</td>
<td><asp:TextBox ID="ClientProductAuthCodeT extBox" runat="server" Text='<%# Bind("ClientProductAuthCod e") %>'></asp:TextBox></td>
</tr>
<tr>
<td align="right">Price:</td>
<td><asp:TextBox ID="ClientProductPriceText Box" runat="server" Text='<%# Bind("ClientProductPrice") %>'></asp:TextBox></td>
</tr>
<tr>
<td align="right">Date:</td>
<td><asp:TextBox ID="ClientProductPurchaseD ateTextBox " runat="server" Text='<%# DateTime.Now.ToString("MM/ dd/yyyy") %>' Enabled="False"></asp:Text Box></td>
</tr>
<tr>
<td align="right">Sales Person:</td>
<td><asp:TextBox ID="ClientProductSoldByTex tBox" 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:ClientDB Connection String %>"
ProviderName="<%$ ConnectionStrings:ClientDB Connection String.Pro viderName %>"
SelectCommand="SELECT * FROM [Clients]"></asp:SqlDataSo urce>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ClientDB Connection String %>"
InsertCommand="INSERT INTO [ClientProducts] ([ClientID], [ClientProduct], [ProductNumber], [ClientProductDesc], [ClientProductVersion], [ClientProductSerialNumber ], [ClientProductCategory], [ClientProductAuthCode], [ClientProductPrice], [ClientProductPurchaseDate ], [ClientProductSoldBy]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
ProviderName="<%$ ConnectionStrings:ClientDB Connection String.Pro viderName %>">
<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="ClientProductSerialN umber" Type="String" />
<asp:Parameter Name="ClientProductCategor y" Type="String" />
<asp:Parameter Name="ClientProductAuthCod e" Type="String" />
<asp:Parameter Name="ClientProductPrice" Type="String" />
<asp:ControlParameter Name="ClientProductPurchas eDate" Type="String" ControlId="ctl00$ContentPl aceHolder1 $FormView1 $ClientPro ductPurcha seDateText Box" PropertyName="Text"/>
<asp:Parameter Name="ClientProductSoldBy" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ClientDB Connection String %>"
ProviderName="<%$ ConnectionStrings:ClientDB Connection String.Pro viderName %>"
SelectCommand="SELECT * FROM [ProductCategories]"></asp :SqlDataSo urce>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:ClientDB Connection String %>"
ProviderName="<%$ ConnectionStrings:ClientDB Connection String.Pro viderName %>"
SelectCommand="SELECT * FROM [Products] WHERE ([ProductCategory] = ?)">
<SelectParameters>
<asp:ControlParameter ControlID="ListBox2" Name="ProductCategory" PropertyName="SelectedValu e"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>
Line 22: DataView dv = (DataView)SqlDataSource4.S
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.
using System.Web.UI.HtmlControls
public partial class addproduct : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ListBox3_SelectedIndexChan
{
if (ListBox3.SelectedIndex > -1)
{
DataView dv = (DataView)SqlDataSource4.S
TextBox tb;
dv.RowFilter = "ProductNumber = " + ListBox3.SelectedValue;
if (dv.Count > 0)
{
tb = (TextBox)FormView1.FindCon
tb.Text = dv[0]["ProductNumber"].ToS
tb = (TextBox)FormView1.FindCon
tb.Text = dv[0]["ProductName"].ToStr
tb = (TextBox)FormView1.FindCon
tb.Text = dv[0]["ProductDescription"
tb = (TextBox)FormView1.FindCon
tb.Text = dv[0]["ProductVersion"].To
tb = (TextBox)FormView1.FindCon
tb.Text = dv[0]["ProductSerialNumber
tb = (TextBox)FormView1.FindCon
tb.Text = dv[0]["ProductCategory"].T
}
}
}
}
Page Code:
<%@ Page Language="C#" MasterPageFile="~/MasterPa
<asp:Content ID="Content1" ContentPlaceHolderID="Cont
<script language="javascript" type="text/javascript">
function doIt(textBoxID)
{
var textBox = document.getElementById(te
textBox.value = document.getElementById("c
}
function doIt2(textBoxID)
{
var textBox = document.getElementById(te
textBox.value = document.getElementById("c
}
function doIt3(textBoxID)
{
var textBox = document.getElementById(te
textBox.value = document.getElementById("c
}
</script>
<table border="0">
<tr>
<td valign="top">
<b>Clients</b><br />
<asp:ListBox ID="ListBox1" runat="server" DataSourceID="SqlDataSourc
DataTextField="ClientCompa
</asp:ListBox>
</td>
<td valign="top" style="width: 3px">
<b>Categories</b><br />
<asp:ListBox ID="ListBox2" runat="server" Height="300px" Width="120px" DataSourceID="SqlDataSourc
</asp:ListBox></td>
<td valign="top">
<b>Products</b><br />
<asp:ListBox ID="ListBox3" runat="server" Height="300px" Width="120px" DataSourceID="SqlDataSourc
</asp:ListBox>
</td>
<td valign="top" style="width: 270px">
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ClientProduc
<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><asp:TextBox ID="ClientProductDescTextB
</tr>
<tr>
<td align="right">Version:</td
<td><asp:TextBox ID="ClientProductVersionTe
</tr>
<tr>
<td align="right">Serial #:</td>
<td><asp:TextBox ID="ClientProductSerialNum
</tr>
<tr>
<td align="right">Category:</t
<td><asp:TextBox ID="ClientProductCategoryT
</tr>
<tr>
<td align="right">Auth Code:</td>
<td><asp:TextBox ID="ClientProductAuthCodeT
</tr>
<tr>
<td align="right">Price:</td>
<td><asp:TextBox ID="ClientProductPriceText
</tr>
<tr>
<td align="right">Date:</td>
<td><asp:TextBox ID="ClientProductPurchaseD
</tr>
<tr>
<td align="right">Sales Person:</td>
<td><asp:TextBox ID="ClientProductSoldByTex
</tr>
<tr>
<td align="right" colspan="2"><asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert"></asp:Button
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
</td>
</tr>
</table>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClientDB
ProviderName="<%$ ConnectionStrings:ClientDB
SelectCommand="SELECT * FROM [Clients]"></asp:SqlDataSo
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ClientDB
InsertCommand="INSERT INTO [ClientProducts] ([ClientID], [ClientProduct], [ProductNumber], [ClientProductDesc], [ClientProductVersion], [ClientProductSerialNumber
ProviderName="<%$ ConnectionStrings:ClientDB
<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
<asp:Parameter Name="ClientProductSerialN
<asp:Parameter Name="ClientProductCategor
<asp:Parameter Name="ClientProductAuthCod
<asp:Parameter Name="ClientProductPrice" Type="String" />
<asp:ControlParameter Name="ClientProductPurchas
<asp:Parameter Name="ClientProductSoldBy"
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ClientDB
ProviderName="<%$ ConnectionStrings:ClientDB
SelectCommand="SELECT * FROM [ProductCategories]"></asp
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:ClientDB
ProviderName="<%$ ConnectionStrings:ClientDB
SelectCommand="SELECT * FROM [Products] WHERE ([ProductCategory] = ?)">
<SelectParameters>
<asp:ControlParameter ControlID="ListBox2" Name="ProductCategory" PropertyName="SelectedValu
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>
what if you put
on line 24
dv.RowFilter = "ProductNumber = " + ListBox3.SelectedValue.ToS tring();
on line 24
dv.RowFilter = "ProductNumber = " + ListBox3.SelectedValue.ToS
ASKER
Nope...didn't change anything.
which line specifically does the error occur
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
doh!! good catch CmdoProg2