當前位置: 首頁>>代碼示例>>C#>>正文


C# DataTable.LoadDataRow方法代碼示例

本文整理匯總了C#中System.Data.DataTable.LoadDataRow方法的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.LoadDataRow方法的具體用法?C# DataTable.LoadDataRow怎麽用?C# DataTable.LoadDataRow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Data.DataTable的用法示例。


在下文中一共展示了DataTable.LoadDataRow方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: aboutList

        public static string aboutList()
        {
            StringBuilder strTxt = new StringBuilder();
            DataTable tbl = new DataTable();
            tbl.Columns.Add("Title", typeof(string));
            tbl.Columns.Add("Url", typeof(string));
            object[] aValues = { "公司簡介", "About.aspx" };
            tbl.LoadDataRow(aValues, true);
            object[] aValues1 = { "招聘信息", "Jobs.aspx" };
            tbl.LoadDataRow(aValues1, true);
            object[] aValues2 = { "站點地圖", "SiteMap.aspx" };
            tbl.LoadDataRow(aValues2, true);
            object[] aValues3 = { "聯係我們", "ContactInfo.aspx" };
            tbl.LoadDataRow(aValues3, true);

            if (tbl.Rows.Count > 0)
            {
                strTxt.Append("<dl>");
                for (int j = 0; j < tbl.Rows.Count; j++)
                {
                    DataRow dr2 = tbl.Rows[j];
                    strTxt.Append("<dd style=\"background-color: rgb(239,239,239); height: 26px;\">");
                    strTxt.Append("<a class=\"channelClass01\" href=\""+ dr2["Url"].ToString() +"\" style=\"position: relative;top: 5px; left: 15px;\">" + dr2["Title"].ToString() + "</a>");
                    strTxt.Append("</dd>");
                }
                strTxt.Append("</dl>");
            }
            else
                strTxt.Append("暫無欄目!");
            return strTxt.ToString();
        }
開發者ID:BGCX261,項目名稱:zhongzhiweb-svn-to-git,代碼行數:31,代碼來源:Channel.cs

示例2: CommasInDataDataTable

 public static DataTable CommasInDataDataTable()
 {
     DataTable dataTable = new DataTable();
     dataTable.Columns.Add("First");
     dataTable.Columns.Add("Second");
     dataTable.Columns.Add("Third");
     dataTable.LoadDataRow(new object[] { "a,a", "b,b", "c,c" }, false);
     dataTable.LoadDataRow(new object[] { "a1,a1", "b1,b1", "c1,c1" }, false);
     return dataTable;
 }
開發者ID:kevinbosman,項目名稱:habanero,代碼行數:10,代碼來源:CsvTestsSamples.cs

示例3: Main

        static void Main(string[] args)
        {
            DataTable cave = new DataTable("Cave"); // création de la table "Cave" (vide pour l'instant)

            DataColumn id = new DataColumn("ID");
            id.DataType = typeof(int);
            id.AutoIncrement = true; // active l'autoincrémentation de la colonne
            id.AutoIncrementSeed = 1; // valeur de départ pour l'autoincrémentation
            id.AutoIncrementStep = 1; // pas pour l'autoincrémentation
            cave.Columns.Add(id);
            cave.PrimaryKey = new DataColumn[] { id }; // désignation de la colonne "ID" comme clé primaire de la table

            DataColumn vin = new DataColumn("Vin"); // création d'une colonne "Vin"
            vin.DataType = typeof(string); // le type de données est string par défaut, cette ligne est donc optionelle
            vin.Unique = true; // détermine si les valeurs de la colonnes doivent être uniques (false par défaut)
            vin.AllowDBNull = false; // détermine si la colonne accepte les valeurs NULL (true par défaut)
            vin.Caption = "Vin"; // nom que portera la colonne dans la représentation graphique (par défaut, c'est le nom de la colonne spécifié lors de la déclaration)
            cave.Columns.Add(vin); // la colonne "Vin" est ajoutée à la table "Cave"

            DataColumn annee = new DataColumn("Annee", typeof(int)); // on peut utiliser le constructeur à 2 paramètres pour déclarer une nouvelle colonne tout en spécifiant son type
            annee.AllowDBNull = false;
            annee.Caption = "Année";
            cave.Columns.Add(annee);

            DataColumn marque = new DataColumn("Marque");
            marque.MaxLength = 35;  // détermine la taille maximale dans le cas d'un string (-1 par défaut, càd illimité)
            marque.AllowDBNull = false;
            cave.Columns.Add(marque);

            // la colonne suivante est une colonne dérivée des colonnes "Marque" et "Année"
            DataColumn marqueEtAnnee = new DataColumn("MarqueEtAnnee");
            marqueEtAnnee.MaxLength = 40;
            marqueEtAnnee.Expression = "Annee + ' ' + Marque"; // la propriété "Expression" permet de concaténer les valeurs de plusieurs colonnes
            marqueEtAnnee.Caption = "Marque et Année";
            cave.Columns.Add(marqueEtAnnee);

            // remplissage de la table
            DataRow newCave = cave.NewRow(); // création de la ligne à insérer
            newCave["Vin"] = "Beaujolais";
            newCave["Marque"] = "Grand Cru";
            newCave["Annee"] = 1982;
            cave.Rows.Add(newCave); // ajout de la ligne à la table "Cave"

            cave.LoadDataRow(new object[] { null, "Bourgogne", 2012, "Prix 2012" }, true); // une autre méthode d'ajout de lignes
            cave.LoadDataRow(new object[] { null, "Saint-Emilion", 1983, "Cuvée Prestige" }, true);
            cave.LoadDataRow(new object[] { null, "Pommard", 1959, "Clos Blanc" }, true);

            printTable(cave);
        }
開發者ID:ZipionLive,項目名稱:ADO-Disconnected,代碼行數:49,代碼來源:Program.cs

示例4: GetRecord

        public DataTable GetRecord()
        {
            FinesStyleInfoRequery finesStyleInfo = new FinesStyleInfoRequery();
            IList iList=finesStyleInfo.FinesInfoRequery(null);
            if (iList == null)
                return null;

            DataTable result = new DataTable();
            if (iList.Count > 0)
            {
                PropertyInfo[] propertys = iList[0].GetType().GetProperties();
                foreach (PropertyInfo pi in propertys)
                {
                    result.Columns.Add(pi.Name, pi.PropertyType);
                }

                for (int i = 0; i < iList.Count; i++)
                {
                    ArrayList tempList = new ArrayList();
                    foreach (PropertyInfo pi in propertys)
                    {
                        object obj = pi.GetValue(iList[i], null);
                        tempList.Add(obj);
                    }
                    object[] array = tempList.ToArray();
                    result.LoadDataRow(array, true);
                }
            }
            return result;
        }
開發者ID:kooyou,項目名稱:TrafficFinesSystem,代碼行數:30,代碼來源:FinesStyleRequery.cs

示例5: getTable

        private static DataTable getTable(string xmlTable_)
    {
      var doc = new System.Xml.XmlDocument();
      doc.LoadXml(xmlTable_);

      DataTable dt = new DataTable();

      foreach (XmlNode rowNode in doc.DocumentElement.SelectNodes("./Table/Rows/Row"))
      {
        if (dt.Columns.Count == 0)
        {
          foreach (XmlNode node in rowNode.SelectNodes("./string"))
            dt.Columns.Add(node.InnerText);
        }
        else
        {
          string[] vals = new string[dt.Columns.Count];
          XmlNodeList list = rowNode.SelectNodes("./string");

          for (int i = 0; i < list.Count; ++i)
            vals[i] = list[i].InnerText;
          dt.LoadDataRow(vals, true);
        }
      }

      return dt;

    }
開發者ID:heimanhon,項目名稱:researchwork,代碼行數:28,代碼來源:Retriever.cs

示例6: GenerateLargeInputTable

		private static DataTable GenerateLargeInputTable()
		{
			var sourceTable = new DataTable();
			sourceTable.Columns.Add("BeginTime", typeof(DateTime));
			sourceTable.Columns.Add("EndTime", typeof(DateTime));
			sourceTable.Columns.Add("TravelTypeId", typeof(short));

			for (var date = new DateTime(1000, 1, 1); date.Year <= 3000; date = date.AddDays(3))
			{
				sourceTable.LoadDataRow(new object[] { date.AddHours(8.0), date.AddHours(10.0), (short)0 }, LoadOption.OverwriteChanges);
				sourceTable.LoadDataRow(new object[] { date.AddHours(17.0), date.AddHours(19.0), (short)1 }, LoadOption.OverwriteChanges);
				sourceTable.LoadDataRow(new object[] { date.AddHours((24.0 * 2) + 17.0), date.AddHours((24.0 * 2) + 19.0), (short)2 }, LoadOption.OverwriteChanges);
			}

			return sourceTable;
		}
開發者ID:mkandroid15,項目名稱:Samples,代碼行數:16,代碼來源:Program.cs

示例7: ConvertDataReaderToDataTable

        public static DataTable ConvertDataReaderToDataTable(DbDataReader reader)
        {
            try
            {
                DataTable table = new DataTable();
                int fieldCount = reader.FieldCount;
                for (int fieldIndex = 0; fieldIndex < fieldCount; ++fieldIndex)
                {
                    table.Columns.Add(reader.GetName(fieldIndex), reader.GetFieldType(fieldIndex));
                }

                table.BeginLoadData();

                object[] rowValues = new object[fieldCount];
                while (reader.Read())
                {
                    reader.GetValues(rowValues);
                    table.LoadDataRow(rowValues, true);
                }
                reader.Close();
                table.EndLoadData();

                return table;

            }
            catch (Exception ex)
            {
                throw new Exception("DataReader轉換為DataTable時出錯!", ex);
            }
        }
開發者ID:piaolingzxh,項目名稱:Justin,代碼行數:30,代碼來源:DBHelper.cs

示例8: ConvertToDataTable

        private static DataTable ConvertToDataTable(object[] excelObjctData, string primaryKeyValue, string colsKeyValue)
        {
            Hashtable colsHash = ParseCols(colsKeyValue);

            DataTable dt = new DataTable();

            if (excelObjctData.Length > 0)
            {
                for (int i = 0; i < ((object[])excelObjctData[0]).Length; i++)
                {
                    dt.Columns.Add(ToTagName(i));
                }

                foreach (object[] objs in excelObjctData)
                {
                    if (objs[ToIndex(primaryKeyValue)] == null)
                    {
                        break;
                    }
                    dt.LoadDataRow(ParseColsType(objs, colsHash), true);

                }

                for (int i = 0; i < ((object[])excelObjctData[0]).Length; i++)
                {
                    if (!colsHash.ContainsKey(ToTagName(i)))
                    {
                        dt.Columns.Remove(ToTagName(i));
                    }
                }
            }
            return dt;
        }
開發者ID:porter1130,項目名稱:C-A,代碼行數:33,代碼來源:ExcelService.cs

示例9: ToDataSet

        /// <summary> 
        /// 集合裝換DataSet 
        /// </summary> 
        /// <param name="list">集合</param> 
        /// <returns></returns> 
        /// 2008-08-01 22:08 HPDV2806 
        public static DataSet ToDataSet(IList p_List)
        {
            DataSet result = new DataSet();
            DataTable _DataTable = new DataTable();
            if (p_List.Count > 0)
            {
                PropertyInfo[] propertys = p_List[0].GetType().GetProperties();
                foreach (PropertyInfo pi in propertys)
                {
                    _DataTable.Columns.Add(pi.Name, pi.PropertyType);
                }

                for (int i = 0; i < p_List.Count; i++)
                {
                    ArrayList tempList = new ArrayList();
                    foreach (PropertyInfo pi in propertys)
                    {
                        object obj = pi.GetValue(p_List[i], null);
                        tempList.Add(obj);
                    }
                    object[] array = tempList.ToArray();
                    _DataTable.LoadDataRow(array, true);
                }
            }
            result.Tables.Add(_DataTable);
            return result;
        }
開發者ID:yuzhiping,項目名稱:HyCtbuEco,代碼行數:33,代碼來源:IListDataSet.cs

示例10: ConverDataReaderToDataTable

 public static DataTable ConverDataReaderToDataTable(IDataReader reader)
 {
     if (reader == null)
     {
         return null;
     }
     DataTable table = new DataTable
     {
         Locale = CultureInfo.InvariantCulture
     };
     int fieldCount = reader.FieldCount;
     for (int i = 0; i < fieldCount; i++)
     {
         table.Columns.Add(reader.GetName(i), reader.GetFieldType(i));
     }
     table.BeginLoadData();
     object[] values = new object[fieldCount];
     while (reader.Read())
     {
         reader.GetValues(values);
         table.LoadDataRow(values, true);
     }
     table.EndLoadData();
     return table;
 }
開發者ID:bookxiao,項目名稱:orisoft,代碼行數:25,代碼來源:DbHelperSQL.cs

示例11: DataReaderToDataSet

        public static DataSet DataReaderToDataSet(IDataReader reader)
        {
            var ds = new DataSet();
            DataTable table;
            do
            {
                int fieldCount = reader.FieldCount;
                table = new DataTable();
                for (int i = 0; i < fieldCount; i++)
                {
                    table.Columns.Add(reader.GetName(i), reader.GetFieldType(i));
                }
                table.BeginLoadData();
                var values = new Object[fieldCount];
                while (reader.Read())
                {
                    reader.GetValues(values);
                    table.LoadDataRow(values, true);
                }
                table.EndLoadData();

                ds.Tables.Add(table);

            } while (reader.NextResult());
            reader.Close();
            return ds;
        }
開發者ID:samnuriu13,項目名稱:APIXERP,代碼行數:27,代碼來源:Util.cs

示例12: load_from_excel_file

        public void load_from_excel_file(string path, int bufferSize, out float[] channel_2, out float[] timeCoordinate, out int count_channel_2)
        {
            var workbook = ExcelLibrary.SpreadSheet.Workbook.Load(path);
            var worksheet = workbook.Worksheets[0];
            var cells = worksheet.Cells;
            var dataTable = new DataTable("datatable");
            // добавить столбцы в таблицу
            dataTable.Columns.Add("force");
            dataTable.Columns.Add("time");
            // добавить строки в таблицу
            for (int rowIndex = cells.FirstRowIndex + 1; rowIndex <= cells.LastRowIndex; rowIndex++)
            {
                var values = new List<string>();
                foreach (var cell in cells.GetRow(rowIndex))
                {
                    values.Add(cell.Value.StringValue);
                }

                dataTable.LoadDataRow(values.ToArray(), true);
            }

            DataRow[] dr = dataTable.Select();
            channel_2 = new float[bufferSize];
            timeCoordinate = new float[bufferSize];
            count_channel_2 = 0;

            foreach (DataRow r in dr)
            {
                channel_2[count_channel_2] = Int16.Parse((string)r[0]);
                timeCoordinate[count_channel_2] = Single.Parse((string)r[1]);
                count_channel_2++;
            }
        }
開發者ID:K0lyuchiy,項目名稱:Tass,代碼行數:33,代碼來源:Excel_Interface.cs

示例13: ListToDataTable

        public static DataTable ListToDataTable(IList ResList)
        {
            DataTable TempDT = new DataTable();

            System.Reflection.PropertyInfo[] p = ResList[0].GetType().GetProperties();
            foreach (System.Reflection.PropertyInfo pi in p)
            {
                TempDT.Columns.Add(pi.Name, System.Type.GetType(pi.PropertyType.ToString()));
            }

            for (int i = 0; i < ResList.Count; i++)
            {
                IList TempList = new ArrayList();
                foreach (System.Reflection.PropertyInfo pi in p)
                {
                    object oo = pi.GetValue(ResList[i], null);
                    TempList.Add(oo);
                }

                object[] itm = new object[p.Length];
                for (int j = 0; j < TempList.Count; j++)
                {
                    itm.SetValue(TempList[j], j);
                }
                TempDT.LoadDataRow(itm, true);
            }
            return TempDT;
        }
開發者ID:CalvertYang,項目名稱:webinspector,代碼行數:28,代碼來源:MapSetup.cs

示例14: Create

    public void Create(ConstructGen<double> candleData_, int openIndex_ = 0, int highIndex_ = 1, int lowIndex_ = 2, int closeIndex_ = 3, int setupLength_=9, int countdownLength_=13)
    {
      var dt = new DataTable();
      dt.Rows.Clear();
      dt.Columns.Clear();

      dt.Columns.Add("Date", typeof(DateTime));
      dt.Columns.Add("Open", typeof(double));
      dt.Columns.Add("High", typeof(double));
      dt.Columns.Add("Low", typeof(double));
      dt.Columns.Add("Close", typeof(double));
      dt.Columns.Add("Volume", typeof(double));

      ultraChart1.DataSource = dt;

      var closes = candleData_.GetColumnValuesAsDDC(closeIndex_);
      var range = closes.Data.Max() - closes.Data.Min();
      var cellHeight = range/10d;


      var setupStarts = DeMarkAnalysis.GetSetups(candleData_,openIndex_,highIndex_,lowIndex_,closeIndex_,setupLength_);
      DeMarkAnalysis.AddCountdowns(candleData_, setupStarts,openIndex_,highIndex_,lowIndex_,closeIndex_,setupLength_,countdownLength_);


      for (int i = 0; i < candleData_.Dates.Count; ++i)
      {
        var date = candleData_.Dates[i];

        var arr = candleData_.GetValues(date);
        dt.LoadDataRow(new object[]
        {
          date,
          arr[openIndex_],
          arr[highIndex_],
          arr[lowIndex_],
          arr[closeIndex_],
          0d
        }, true);

        foreach(var mark in setupStarts)
        {
          addAnnotations(date, mark, i, cellHeight, arr,openIndex_,highIndex_,lowIndex_,closeIndex_);
        }
      }

      EstablishDefaultTooltip(hash =>
      {
        int rowNumber = (int) hash["DATA_ROW"];

        return string.Format("{0} Open: {1}, High: {2}, Low: {3}, Close: {4}",
          ((DateTime) dt.Rows[rowNumber]["Date"]).ToString("dd-MMM-yyyy"),
          ((double) dt.Rows[rowNumber]["Open"]).ToString(CultureInfo.InvariantCulture),
          ((double)dt.Rows[rowNumber]["High"]).ToString(CultureInfo.InvariantCulture),
          ((double)dt.Rows[rowNumber]["Low"]).ToString(CultureInfo.InvariantCulture),
          ((double)dt.Rows[rowNumber]["Close"]).ToString(CultureInfo.InvariantCulture)
          ).Replace(",", System.Environment.NewLine);

      });
    }
開發者ID:heimanhon,項目名稱:researchwork,代碼行數:59,代碼來源:DeMarkChart3.cs

示例15: SimpleDataTable

 public static DataTable SimpleDataTable()
 {
     DataTable dataTable = new DataTable();
     dataTable.Columns.Add("First");
     dataTable.Columns.Add("2nd");
     dataTable.Columns.Add("3");
     dataTable.LoadDataRow(new object[] { "a", "b", "c" }, false);
     return dataTable;
 }
開發者ID:kevinbosman,項目名稱:habanero,代碼行數:9,代碼來源:CsvTestsSamples.cs


注:本文中的System.Data.DataTable.LoadDataRow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。