开发者

Display Query results in a DataGrid View

开发者 https://www.devze.com 2023-03-12 08:11 出处:网络
I am working on a C# application that writes to a database whenever new info comes in through a file. Then, when the user wants to get some specific information, he queries th开发者_运维技巧e database

I am working on a C# application that writes to a database whenever new info comes in through a file. Then, when the user wants to get some specific information, he queries th开发者_运维技巧e database and then, based on the query, whatever info is there in the database must be displayed in a datagrid view.

So, the database(LogDatabase) here has three fields, 1.Timestamp 2.LogMessage and 3.Hash I send queries to the database looking for the word "ERR" in the LogMessage field. The lines that contain this must be displayed in the datagridview called "query_dataview".

What must i do? I've sent queries to count the occurance of "ERR" and they worked. But I am not able to display the information in a datagrid. Please help

logDatabaseTableAdapter_query
    .Connection.ConnectionString = "data source=C:\\TMU_Files\\test33.s3db";
logDatabaseTableAdapter_query
    .Fill(this.logDatabaseDataSet_query.LogDatabase);

This is what i did to fill the entire database into another datagrid view. So, Now I want to use only those entries that satisfy the requirements of the query sent.


    var logDatabaseTableAdapter_queryselect = new SQLiteDataAdapter(("SELECT * from         LogDatabase where LogMessage like '%ERR%'"), "data source=C:\\TMU_Files\\test24.s3db");
    logDatabaseTableAdapter_queryselect.Fill(logDatabaseDataSet_query.LogDatabase);

used this above piece of code to write onto the database. Works now... Its just important to give all the connections properly. As in, the datasource for the datagridview and then the binding source, the data-adapter and dataset..

The msdn example code for data-table helps a lot.

Thanks.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号