D
Dotnet Gruven
I'm trying to use a typed dataset and ObjectDataSource binding to a SQLX db
using a foreign key to filter the returned result set to display in a
GridView.
The error message in the subject line is generated when I try to bind the
following GridView to the ObjectSource that follows and the code that
follows that which is from an ASP.NET form PageLoad:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
SelectMethod="FillMenusByLocation"
TypeName="RestaurantsTableAdapters.MenusTableAdapter"
UpdateMethod="Update">
<DeleteParameters>
<asparameter Name="Original_MenuId" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="LocationId" Type="Int32" />
<asparameter Name="MenuName" Type="String" />
<asparameter Name="IsAvailable" Type="Boolean" />
<asparameter Name="DisplayOrder" Type="Int32" />
<asparameter Name="Original_MenuId" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="LocationId" Type="Int32" />
<asparameter Name="MenuName" Type="String" />
<asparameter Name="IsAvailable" Type="Boolean" />
<asparameter Name="DisplayOrder" Type="Int32" />
</InsertParameters>
</asp:ObjectDataSource>
---------------------------------------------------
<asp:GridView ID="MenusGridView" Runat="server"
DataSourceID="ObjectDataSource1" DataKeyNames="LocationId" ShowHeader=True
AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="Both" >
<Columns>
<asp:BoundField ReadOnly="True" HeaderText="MenuId" DataField="MenuId"
SortExpression="MenuId" Visible=True />
<asp:BoundField ReadOnly="True" HeaderText="LocationId"
DataField="LocationId" SortExpression="LocationId" Visible=True />
<asp:BoundField HeaderText="Name" DataField="MenuName"
SortExpression="MenuName" />
<asp:CheckBoxField HeaderText="Available?" DataField="IsAvailable"
SortExpression="IsAvailable" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField HeaderText="DisplayOrder" DataField="DisplayOrder"
SortExpression="DisplayOrder" />
</Columns>
</asp:GridView>
--------- From Page_Load !IsPostBack
ObjectDataSource1.SelectParameters.Add("@parameter1", TypeCode.Int32,
locationId.ToString());
----------
Here is the XSD for the related TableAdapter
<TableAdapter BaseClass="System.ComponentModel.Component"
DataAccessorName="MenusTableAdapter" Modifier="AutoLayout, AnsiClass, Class,
Public" Name="Menus" WebServiceAttribute="False">
<MainSource>
<DbSource ConnectionRef="ASPNETDBConnectionString (Web.config)"
DbObjectName="dbo.Menus" DbObjectType="Table" EnableWebMethods="False"
FillMethodModifier="Public" FillMethodName="Fill" GenerateMethods="Both"
GeneratePagingMethods="False" GenerateShortCommands="True"
GetMethodName="GetData" QueryType="Rowset" ScalarCallRetval="System.Object,
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
UseOptimisticConcurrency="False">
<DeleteCommand>
<DbCommand CommandType="Text" ModifiedByUser="False">
<CommandText>DELETE FROM [dbo].[Menus] WHERE (([MenuId] =
@Original_MenuId))</CommandText>
<Parameters>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Int32" Direction="Input" ParameterName="@Original_MenuId"
Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="MenuId"
SourceColumnNullMapping="False" SourceVersion="Original">
</Parameter>
</Parameters>
</DbCommand>
</DeleteCommand>
<InsertCommand>
<DbCommand CommandType="Text" ModifiedByUser="False">
<CommandText>INSERT INTO [dbo].[Menus] ([LocationId], [MenuName],
[IsAvailable], [DisplayOrder]) VALUES (@LocationId, @MenuName, @IsAvailable,
@DisplayOrder)</CommandText>
<Parameters>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Int32" Direction="Input" ParameterName="@LocationId" Precision="0"
ProviderType="Int" Scale="0" Size="0" SourceColumn="LocationId"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="String" Direction="Input" ParameterName="@MenuName" Precision="0"
ProviderType="NVarChar" Scale="0" Size="0" SourceColumn="MenuName"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Boolean" Direction="Input" ParameterName="@IsAvailable"
Precision="0" ProviderType="Bit" Scale="0" Size="0"
SourceColumn="IsAvailable" SourceColumnNullMapping="False"
SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Int32" Direction="Input" ParameterName="@DisplayOrder" Precision="0"
ProviderType="Int" Scale="0" Size="0" SourceColumn="DisplayOrder"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
</Parameters>
</DbCommand>
</InsertCommand>
<SelectCommand>
<DbCommand CommandType="Text" ModifiedByUser="True">
<CommandText>SELECT MenuId, LocationId, MenuName, IsAvailable, DisplayOrder
FROM Menus</CommandText>
<Parameters>
</Parameters>
</DbCommand>
</SelectCommand>
<UpdateCommand>
<DbCommand CommandType="Text" ModifiedByUser="False">
<CommandText>UPDATE [dbo].[Menus] SET [LocationId] = @LocationId, [MenuName]
= @MenuName, [IsAvailable] = @IsAvailable, [DisplayOrder] = @DisplayOrder
WHERE (([MenuId] = @Original_MenuId))</CommandText>
<Parameters>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Int32" Direction="Input" ParameterName="@LocationId" Precision="0"
ProviderType="Int" Scale="0" Size="0" SourceColumn="LocationId"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="String" Direction="Input" ParameterName="@MenuName" Precision="0"
ProviderType="NVarChar" Scale="0" Size="0" SourceColumn="MenuName"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Boolean" Direction="Input" ParameterName="@IsAvailable"
Precision="0" ProviderType="Bit" Scale="0" Size="0"
SourceColumn="IsAvailable" SourceColumnNullMapping="False"
SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Int32" Direction="Input" ParameterName="@DisplayOrder" Precision="0"
ProviderType="Int" Scale="0" Size="0" SourceColumn="DisplayOrder"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Int32" Direction="Input" ParameterName="@Original_MenuId"
Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="MenuId"
SourceColumnNullMapping="False" SourceVersion="Original">
</Parameter>
</Parameters>
</DbCommand>
</UpdateCommand>
</DbSource>
</MainSource>
<Mappings>
<Mapping SourceColumn="MenuId" DataSetColumn="MenuId" />
<Mapping SourceColumn="LocationId" DataSetColumn="LocationId" />
<Mapping SourceColumn="MenuName" DataSetColumn="MenuName" />
<Mapping SourceColumn="IsAvailable" DataSetColumn="IsAvailable" />
<Mapping SourceColumn="DisplayOrder" DataSetColumn="DisplayOrder" />
</Mappings>
<Sources>
<DbSource ConnectionRef="ASPNETDBConnectionString (Web.config)"
DbObjectName="dbo.Menus" DbObjectType="Table" EnableWebMethods="False"
FillMethodModifier="Public" FillMethodName="FillMenusByLocation"
GenerateMethods="Both" GeneratePagingMethods="False"
GenerateShortCommands="True" GetMethodName="GetMenusByLocation"
QueryType="Rowset" ScalarCallRetval="System.Object, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
UseOptimisticConcurrency="True">
<SelectCommand>
<DbCommand CommandType="Text" ModifiedByUser="True">
<CommandText>SELECT MenuId, MenuName, IsAvailable, DisplayOrder
FROM Menus
WHERE (LocationId = @parameter1)</CommandText>
<Parameters>
<Parameter AllowDbNull="False" AutogeneratedName="parameter1"
ColumnName="LocationId"
DataSourceName="[C:\SHARE\xyzzy\xyzzy\APP_DATA\ASPNETDB.MDF].dbo.Menus"
DataTypeServer="int" DbType="Int32" Direction="Input"
ParameterName="@parameter1" Precision="0" ProviderType="Int" Scale="0"
Size="4" SourceColumn="LocationId" SourceColumnNullMapping="False"
SourceVersion="Current">
</Parameter>
</Parameters>
</DbCommand>
</SelectCommand>
</DbSource>
</Sources>
</TableAdapter>
using a foreign key to filter the returned result set to display in a
GridView.
The error message in the subject line is generated when I try to bind the
following GridView to the ObjectSource that follows and the code that
follows that which is from an ASP.NET form PageLoad:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
SelectMethod="FillMenusByLocation"
TypeName="RestaurantsTableAdapters.MenusTableAdapter"
UpdateMethod="Update">
<DeleteParameters>
<asparameter Name="Original_MenuId" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="LocationId" Type="Int32" />
<asparameter Name="MenuName" Type="String" />
<asparameter Name="IsAvailable" Type="Boolean" />
<asparameter Name="DisplayOrder" Type="Int32" />
<asparameter Name="Original_MenuId" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="LocationId" Type="Int32" />
<asparameter Name="MenuName" Type="String" />
<asparameter Name="IsAvailable" Type="Boolean" />
<asparameter Name="DisplayOrder" Type="Int32" />
</InsertParameters>
</asp:ObjectDataSource>
---------------------------------------------------
<asp:GridView ID="MenusGridView" Runat="server"
DataSourceID="ObjectDataSource1" DataKeyNames="LocationId" ShowHeader=True
AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="Both" >
<Columns>
<asp:BoundField ReadOnly="True" HeaderText="MenuId" DataField="MenuId"
SortExpression="MenuId" Visible=True />
<asp:BoundField ReadOnly="True" HeaderText="LocationId"
DataField="LocationId" SortExpression="LocationId" Visible=True />
<asp:BoundField HeaderText="Name" DataField="MenuName"
SortExpression="MenuName" />
<asp:CheckBoxField HeaderText="Available?" DataField="IsAvailable"
SortExpression="IsAvailable" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField HeaderText="DisplayOrder" DataField="DisplayOrder"
SortExpression="DisplayOrder" />
</Columns>
</asp:GridView>
--------- From Page_Load !IsPostBack
ObjectDataSource1.SelectParameters.Add("@parameter1", TypeCode.Int32,
locationId.ToString());
----------
Here is the XSD for the related TableAdapter
<TableAdapter BaseClass="System.ComponentModel.Component"
DataAccessorName="MenusTableAdapter" Modifier="AutoLayout, AnsiClass, Class,
Public" Name="Menus" WebServiceAttribute="False">
<MainSource>
<DbSource ConnectionRef="ASPNETDBConnectionString (Web.config)"
DbObjectName="dbo.Menus" DbObjectType="Table" EnableWebMethods="False"
FillMethodModifier="Public" FillMethodName="Fill" GenerateMethods="Both"
GeneratePagingMethods="False" GenerateShortCommands="True"
GetMethodName="GetData" QueryType="Rowset" ScalarCallRetval="System.Object,
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
UseOptimisticConcurrency="False">
<DeleteCommand>
<DbCommand CommandType="Text" ModifiedByUser="False">
<CommandText>DELETE FROM [dbo].[Menus] WHERE (([MenuId] =
@Original_MenuId))</CommandText>
<Parameters>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Int32" Direction="Input" ParameterName="@Original_MenuId"
Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="MenuId"
SourceColumnNullMapping="False" SourceVersion="Original">
</Parameter>
</Parameters>
</DbCommand>
</DeleteCommand>
<InsertCommand>
<DbCommand CommandType="Text" ModifiedByUser="False">
<CommandText>INSERT INTO [dbo].[Menus] ([LocationId], [MenuName],
[IsAvailable], [DisplayOrder]) VALUES (@LocationId, @MenuName, @IsAvailable,
@DisplayOrder)</CommandText>
<Parameters>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Int32" Direction="Input" ParameterName="@LocationId" Precision="0"
ProviderType="Int" Scale="0" Size="0" SourceColumn="LocationId"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="String" Direction="Input" ParameterName="@MenuName" Precision="0"
ProviderType="NVarChar" Scale="0" Size="0" SourceColumn="MenuName"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Boolean" Direction="Input" ParameterName="@IsAvailable"
Precision="0" ProviderType="Bit" Scale="0" Size="0"
SourceColumn="IsAvailable" SourceColumnNullMapping="False"
SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Int32" Direction="Input" ParameterName="@DisplayOrder" Precision="0"
ProviderType="Int" Scale="0" Size="0" SourceColumn="DisplayOrder"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
</Parameters>
</DbCommand>
</InsertCommand>
<SelectCommand>
<DbCommand CommandType="Text" ModifiedByUser="True">
<CommandText>SELECT MenuId, LocationId, MenuName, IsAvailable, DisplayOrder
FROM Menus</CommandText>
<Parameters>
</Parameters>
</DbCommand>
</SelectCommand>
<UpdateCommand>
<DbCommand CommandType="Text" ModifiedByUser="False">
<CommandText>UPDATE [dbo].[Menus] SET [LocationId] = @LocationId, [MenuName]
= @MenuName, [IsAvailable] = @IsAvailable, [DisplayOrder] = @DisplayOrder
WHERE (([MenuId] = @Original_MenuId))</CommandText>
<Parameters>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Int32" Direction="Input" ParameterName="@LocationId" Precision="0"
ProviderType="Int" Scale="0" Size="0" SourceColumn="LocationId"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="String" Direction="Input" ParameterName="@MenuName" Precision="0"
ProviderType="NVarChar" Scale="0" Size="0" SourceColumn="MenuName"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Boolean" Direction="Input" ParameterName="@IsAvailable"
Precision="0" ProviderType="Bit" Scale="0" Size="0"
SourceColumn="IsAvailable" SourceColumnNullMapping="False"
SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Int32" Direction="Input" ParameterName="@DisplayOrder" Precision="0"
ProviderType="Int" Scale="0" Size="0" SourceColumn="DisplayOrder"
SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="False" AutogeneratedName="" DataSourceName=""
DbType="Int32" Direction="Input" ParameterName="@Original_MenuId"
Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="MenuId"
SourceColumnNullMapping="False" SourceVersion="Original">
</Parameter>
</Parameters>
</DbCommand>
</UpdateCommand>
</DbSource>
</MainSource>
<Mappings>
<Mapping SourceColumn="MenuId" DataSetColumn="MenuId" />
<Mapping SourceColumn="LocationId" DataSetColumn="LocationId" />
<Mapping SourceColumn="MenuName" DataSetColumn="MenuName" />
<Mapping SourceColumn="IsAvailable" DataSetColumn="IsAvailable" />
<Mapping SourceColumn="DisplayOrder" DataSetColumn="DisplayOrder" />
</Mappings>
<Sources>
<DbSource ConnectionRef="ASPNETDBConnectionString (Web.config)"
DbObjectName="dbo.Menus" DbObjectType="Table" EnableWebMethods="False"
FillMethodModifier="Public" FillMethodName="FillMenusByLocation"
GenerateMethods="Both" GeneratePagingMethods="False"
GenerateShortCommands="True" GetMethodName="GetMenusByLocation"
QueryType="Rowset" ScalarCallRetval="System.Object, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
UseOptimisticConcurrency="True">
<SelectCommand>
<DbCommand CommandType="Text" ModifiedByUser="True">
<CommandText>SELECT MenuId, MenuName, IsAvailable, DisplayOrder
FROM Menus
WHERE (LocationId = @parameter1)</CommandText>
<Parameters>
<Parameter AllowDbNull="False" AutogeneratedName="parameter1"
ColumnName="LocationId"
DataSourceName="[C:\SHARE\xyzzy\xyzzy\APP_DATA\ASPNETDB.MDF].dbo.Menus"
DataTypeServer="int" DbType="Int32" Direction="Input"
ParameterName="@parameter1" Precision="0" ProviderType="Int" Scale="0"
Size="4" SourceColumn="LocationId" SourceColumnNullMapping="False"
SourceVersion="Current">
</Parameter>
</Parameters>
</DbCommand>
</SelectCommand>
</DbSource>
</Sources>
</TableAdapter>