Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you create a Datatable in wpf?

I'm writing an application in c# using wpf and i was wondering how do you create a data table in wpf? This is a really dumb question, i'm aware, but it doesn't appear like i'm using the correct references as the data table object never appears when i try to create it. My references are as follows:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;
using System.Linq;
using System.ComponentModel;
using System.Data.Sql;
like image 699
user2859487 Avatar asked Nov 23 '25 05:11

user2859487


1 Answers

Here's a method that creates a DataTable...

    private void CreateDataTable()
    {
        System.Data.DataTable dt = new DataTable("MyTable");
        dt.Columns.Add("MyColumn", typeof (string));
        dt.Rows.Add("row of data");
    }

The relevant assembly (as identified by HighCore in the commentary) is System.Data. If it is not included in your references, you can add it via the 'add reference' context menu.

like image 177
Gayot Fow Avatar answered Nov 25 '25 19:11

Gayot Fow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!