C# SQLiteDataAdapter filled DataTable with wrong ColumnName

Viewed 32

In my program, there is a code that writes a Record to the DataTable passed by reference using SQLiteDataAdapter and returns it.

However, there was a problem in which a ColumnName different from the executed query was set in the DataTable under some circumstances.

I'm expecting the problem to be that some case of ColumnName is automatically converted and applied, but I have no idea if it is correct and how to solve it.

This problem does not occur in other DBs or Tables that use the same ColumnName, but this problem is still occurring in the DB and Table where this problem was discovered.

Have these issues been further identified before?

How can I solve this problem?

Query:

SELECT C_ChatRoomId FROM ChatroomInfoTable

Return:

ColumnName = C_ChatRoomID
Records = 0 

ChatroomInfoTable has 3 records

Function:

public bool Select_Table(ref DataTable table, string query, string connStr)
{
    bool result = true;

    using (SQLiteConnection dbConnection = new SQLiteConnection(connStr))
    using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(query, dbConnection))
    using (SQLiteCommand command = dbConnection.CreateCommand())
    {
        command.CommandText = query;
        adapter.SelectCommand = command;
        
        using (SQLiteCommandBuilder builder = new SQLiteCommandBuilder())
        {
            builder.DataAdapter = adapter;
            adapter.Fill(table);
        }
    }

    return result;
}
0 Answers
Related