سلام 😉 در این مطلب کد ساخت DataColumn و افزودن آن به DataTable در سی شارپ #C را آماده کردم. انشاالله که این کد براتون مفید باشه.
کد ساخت DataColumn و افزودن آن به DataTable در سی شارپ #C :
using System;
using System.Data;
class Program
{
static void Main(string[] args)
{
DataTable dt = new DataTable();
DataColumn col1 = dt.Columns.Add();
col1.ColumnName= "First Column";
col1.DataType = typeof(int);
col1.DefaultValue = 0;
col1.Unique = true;
col1.AllowDBNull = false;
DataColumn col2 = new DataColumn();
col2.ColumnName = "Second Column";
col2.DataType = typeof(string);
using System.Data;
class Program
{
static void Main(string[] args)
{
DataTable dt = new DataTable();
DataColumn col1 = dt.Columns.Add();
col1.ColumnName= "First Column";
col1.DataType = typeof(int);
col1.DefaultValue = 0;
col1.Unique = true;
col1.AllowDBNull = false;
DataColumn col2 = new DataColumn();
col2.ColumnName = "Second Column";
col2.DataType = typeof(string);