My Table has 10 columns fetched from a database, while I need to bind only 4 columns of it to a DataGridView in that 4 column 3 columns from database one of them should add dynamically(This column not in database) extra Windows application c#
string sql1 = "Select * From Table";
SqlConnection connection1 = new SqlConnection(constring);
SqlDataAdapter dataadapter = new SqlDataAdapter(sql1, connection1);
DataSet ds1 = new DataSet();
connection1.Open();
dataadapter.Fill(ds1, Reporttype_tbl1);
connection1.Close();
dataGridView2.DataSource = ds1;
dataGridView2.DataMember = Reporttype_tbl1;
If you need extra processing beyond the data that you have in your table you could:
(Imagine that you want to calculate the revenue, giving the income and expenses of a business)
For example: SELECT Name, Income, Expenses, Revenue = Income - Expenses FROM TABLE
In this case, the Revenue will be calculated as the query runs.
For example:
In this case, you are adding the data after the query has been completed, using your C# code to the calculations.
Picking the right one depends on whats kind of work you are wanting to do and what you feel more comfortable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.