I am getting double data (double columns) from my query on a table.
I am unable to fathom why this is happening.
Have tried all kinds of methods but no change.
The original table only has a single row of data in each row.
DataTable dt = new DataTable();
BindingSource SBind = new BindingSource();
List<object> rows = new List<object>();
rows = (List<object>)Get_All_Items_For_A_Table(SelectedTableName);
SBind.DataSource = rows;
dataGridView1.DataSource = SBind;
The data row is too long to post here.
public static object Get_All_Items_For_A_Table(string tableName)
{
object output = null;
string dBaseName = ConfigurationManager.AppSettings.Get("dBaseName");
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(ConnectionStringHelper.CnnVal(dBaseName)))
{
output = connection.Query<object>("dbo.Select_All_From_Table_By_Table_Name", new
{
Table_Name = tableName }, commandType: CommandType.StoredProcedure);
return output;
}
}
I was expecting that as usual, I would get a single row for each row in the datagridview.
The only difference between this query and all the others that work fine is the use of a specific data model to collect the data from the server.
This time I wanted to use a generic model (object) and use a variable for the table name to make the query against.
It all goes well until binding to the Datagridview.
What I have tried:
I have tried all the suggested methods on here and other sites but none of them solve the problem.
Just thought I should post the stored procedure as well:
CREATE PROCEDURE [dbo].[Select_All_From_Table_By_Table_Name]
@Table_Name nvarchar (128)
AS
BEGIN
SET NOCOUNT ON;
SET @table_Name = @Table_Name
DECLARE @sql NVARCHAR(100) = 'SELECT * FROM ' + @table_name;
EXECUTE (@sql);
END
GO
Update: I have tested the stored procedure and it does what is expected. I have watched the value of TableName and it is as expected.
I guess I will have to abandon my attempt to solve this one for a while and develop multiple queries using the data models for each table.
Cheers and thanks for responding.