I face the problem with datasource of datagridview which uses stored procedure and the error is
The data reader is incompatible with the specified 'DatabaseModel.GetInfo_Result'. A member of the type, 'CategoryExpensesId', does not have a corresponding column in the data reader with the same name`.
The stored procedure that I use:
Create PROCEDURE [dbo].[GetInfo] AS
Begin
SELECT [Period] ,[Cost] ,[Name] ,[Comments]
FROM [dbo].[Expenses] as с
inner join [dbo].[CategoryExpenses] as cat on
с.CategoryExpensesId=cat.Id
End
[CategoryExpenses] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Name] NVARCHAR (50) NOT NULL,`--I want to use this column in stored procedure with inner join so that datagridview shows name of category instead of Id`
PRIMARY KEY CLUSTERED ([Id] ASC)
[dbo].[Expenses] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Period] DATETIME2 (7) NOT NULL,
[Cost] DECIMAL (18) NOT NULL,
[Comments] NVARCHAR (MAX) NULL,
[CategoryExpensesId] INT NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Expenses_ToTable] FOREIGN KEY ([CategoryExpensesId]) REFERENCES [dbo].[CategoryExpenses] ([Id])
);
C# code
void PopulateComboboxWithDataGrid()
{
btnDelete.Enabled = false;
dataGridView1.DataSource = db.GetInfo().ToList();
cbxCategory.DataSource = db.CategoryExpenses.ToList();
cbxCategory.ValueMember = "Id";
cbxCategory.DisplayMember = "Name";
cbxCategory.SelectedItem = null;
cbxCategory.SelectedText = "--ChooseCategory--";
}