0

Hi
I get the error Invalid column name 'MakerID' from my code below.

<asp:GridView ID="GridView1"  AllowSorting="true" AllowPaging="true" runat="server" DataSourceID="SqlDataSource1"
AutoGenerateDeleteButton="true" AutoGenerateEditButton="true" DataKeyNames="CamID"AutoGenerateColumns="False">
<Columns>
<asp:BoundField Visible="false" ReadOnly="true" HeaderText="ID" DataField="CamID" 	SortExpression="CamID" />
<asp:BoundField HeaderText="Kamera" DataField="CamName" SortExpression="CamName" />
<asp:BoundField HeaderText="MakerID" DataField="MakerID" SortExpression="MakerID" />
<asp:TemplateField HeaderText="Tillverkare">
<EditItemTemplate>
<asp:SqlDataSource SelectCommand="Select * from Maker" ConnectionString="<%$ ConnectionStrings:CamConnString %>"
ID="SqlDSMaker" runat="server"></asp:SqlDataSource>
<asp:DropDownList ID="ddlMaker" runat="server" AppendDataBoundItems="true" DataSourceID="SqlDSMaker"
DataTextField="MakerName" DataValueField="MakerID" AutoPostBack="True" SelectedValue='<%# Eval("MakerID") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:SqlDataSource SelectCommand="Select * from Maker" ConnectionString="<%$ ConnectionStrings:CamConnString %>"
ID="SqlDSMaker" runat="server"></asp:SqlDataSource>
<asp:DropDownList ID="ddlMaker1" runat="server" AppendDataBoundItems="true" DataSourceID="SqlDSMaker"
DataTextField="MakerName" DataValueField="MakerID" AutoPostBack="True" SelectedValue='<%# Eval("MakerID") %>'>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Megapixels" DataField="MegaPix" SortExpression="MegaPix" />
<asp:BoundField HeaderText="Pris" DataField="Price" SortExpression="Price" />
<asp:BoundField HeaderText="Antal" DataField="Quantity" SortExpression="Quantity" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="select CamID, CamName,MakerName,MegaPix,Price,Quantity,MakerID from DigCameras,Maker where Maker =MakerID" UpdateCommand="UPDATE [DigCameras] SET [CamName] = @CamName, [MakerID] = @MakerID, [MegaPix] = @MegaPix, [Price] = @Price, [Quantity] = @Quantity WHERE [CamID] = @CamID"
DeleteCommand ="Delete DigCameras where CamID=@CamID"
ConnectionString="<%$ ConnectionStrings:CamConnString %>" >
</asp:SqlDataSource>

I have never used the control GridView before, and I don't know if I have insertred the dropdownlist correctly. But I want to have a dropdownlist for the user to choose the Maker from the table Maker.

Please help me
And if you can explain thorougly, please do, what I need to do to make it work.

Thanks
Fia

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by dnanetwork
1

Are you using the C# code behind as well ????.......If yes then plz check the MakerID coloumn name in that.........

0

I believe the problem is with your SelectCommand in SqlDataSource1. you are using two tables in Select Query. It seems like the problem is in Where clause, you have written Maker = MakerID..

I say instead of this write the query like below :

select CamID, CamName,MakerName,MegaPix,Price,Quantity,MakerID from DigCameras,Maker where Maker.MakerID = DigCameras.MakerID

========================================================================================

Hi
I get the error Invalid column name 'MakerID' from my code below.

<asp:GridView ID="GridView1"  AllowSorting="true" AllowPaging="true" runat="server" DataSourceID="SqlDataSource1"
AutoGenerateDeleteButton="true" AutoGenerateEditButton="true" DataKeyNames="CamID"AutoGenerateColumns="False">
<Columns>
<asp:BoundField Visible="false" ReadOnly="true" HeaderText="ID" DataField="CamID" 	SortExpression="CamID" />
<asp:BoundField HeaderText="Kamera" DataField="CamName" SortExpression="CamName" />
<asp:BoundField HeaderText="MakerID" DataField="MakerID" SortExpression="MakerID" />
<asp:TemplateField HeaderText="Tillverkare">
<EditItemTemplate>
<asp:SqlDataSource SelectCommand="Select * from Maker" ConnectionString="<%$ ConnectionStrings:CamConnString %>"
ID="SqlDSMaker" runat="server"></asp:SqlDataSource>
<asp:DropDownList ID="ddlMaker" runat="server" AppendDataBoundItems="true" DataSourceID="SqlDSMaker"
DataTextField="MakerName" DataValueField="MakerID" AutoPostBack="True" SelectedValue='<%# Eval("MakerID") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:SqlDataSource SelectCommand="Select * from Maker" ConnectionString="<%$ ConnectionStrings:CamConnString %>"
ID="SqlDSMaker" runat="server"></asp:SqlDataSource>
<asp:DropDownList ID="ddlMaker1" runat="server" AppendDataBoundItems="true" DataSourceID="SqlDSMaker"
DataTextField="MakerName" DataValueField="MakerID" AutoPostBack="True" SelectedValue='<%# Eval("MakerID") %>'>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Megapixels" DataField="MegaPix" SortExpression="MegaPix" />
<asp:BoundField HeaderText="Pris" DataField="Price" SortExpression="Price" />
<asp:BoundField HeaderText="Antal" DataField="Quantity" SortExpression="Quantity" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="select CamID, CamName,MakerName,MegaPix,Price,Quantity,MakerID from DigCameras,Maker where Maker =MakerID" UpdateCommand="UPDATE [DigCameras] SET [CamName] = @CamName, [MakerID] = @MakerID, [MegaPix] = @MegaPix, [Price] = @Price, [Quantity] = @Quantity WHERE [CamID] = @CamID"
DeleteCommand ="Delete DigCameras where CamID=@CamID"
ConnectionString="<%$ ConnectionStrings:CamConnString %>" >
</asp:SqlDataSource>

I have never used the control GridView before, and I don't know if I have insertred the dropdownlist correctly. But I want to have a dropdownlist for the user to choose the Maker from the table Maker.

Please help me
And if you can explain thorougly, please do, what I need to do to make it work.

Thanks
Fia

0

Hi again

Sorry I didn't explain when the error happens. It's when I'm trying to update after I have edit a row.

Thanks
Fia

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.