当前位置: 首页>>代码示例>>C#>>正文


C# DataSet.Load方法代码示例

本文整理汇总了C#中DataSet.Load方法的典型用法代码示例。如果您正苦于以下问题:C# DataSet.Load方法的具体用法?C# DataSet.Load怎么用?C# DataSet.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataSet的用法示例。


在下文中一共展示了DataSet.Load方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        string connStr = "Data Source=.\\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI;";

        using (SqlConnection conn = new SqlConnection(connStr))
        {
            SqlCommand command = new SqlCommand("select * from customers", conn);
            conn.Open();
            DataSet ds = new DataSet();
            ds.DataSetName = "Customers";
            ds.Load(command.ExecuteReader(), LoadOption.OverwriteChanges, "Customer");
            //Response.ContentType = "text/xml";
            //ds.WriteXml(Response.OutputStream);

            //Added in Listing 13-15
            XmlDataDocument doc = new XmlDataDocument(ds);
            doc.DataSet.EnforceConstraints = false;
            XmlNode node = doc.SelectSingleNode(@"//Customer[CustomerID = 'ANATR']/ContactTitle");
            node.InnerText = "Boss";
            doc.DataSet.EnforceConstraints = true;

            DataRow dr = doc.GetRowFromElement((XmlElement)node.ParentNode);
            Response.Write(dr["ContactName"].ToString() + " is the ");
            Response.Write(dr["ContactTitle"].ToString());
        }
    }
开发者ID:kacecode,项目名称:SchoolWork,代码行数:26,代码来源:Default.aspx.cs

示例2: GetDonationAmount

    public DataSet GetDonationAmount()
    {
        DataSet ds = new DataSet();
        string sql = "Select DonationDate, '$' + Cast(Cast(DonationAmount as decimal(8,2)) as nvarchar) as DonationAmount  from Donation where [email protected]";
        SqlCommand cmd = new SqlCommand(sql, connect);
        cmd.Parameters.AddWithValue("@personKey", pKey);
        SqlDataReader reader = null;

        connect.Open();
        reader = cmd.ExecuteReader();
        ds.Load(reader, LoadOption.OverwriteChanges, "Donations");
        reader.Close();
        connect.Close();
        return ds;
    }
开发者ID:spconger,项目名称:Assignment5Example,代码行数:15,代码来源:DonorGet.cs

示例3: GetName

    public DataSet GetName()
    {
        DataSet ds = new DataSet();
        string sql = "Select LastName, FirstName From Person Where personkey = @PersonKey";
        SqlCommand cmd = new SqlCommand(sql, connect);
        cmd.Parameters.AddWithValue("@PersonKey", pKey);
        SqlDataReader reader = null;

        connect.Open();
        reader = cmd.ExecuteReader();
        ds.Load(reader, LoadOption.OverwriteChanges, "Customer");
        reader.Close();
        connect.Close();

        return ds;
    }
开发者ID:skocode,项目名称:FinalProject,代码行数:16,代码来源:GetCustomer.cs

示例4: getLocationGroupById

 public static DataSet getLocationGroupById(int groupId)
 {
     string sql = "select location_groupid,groupname from location_group where location_groupid=?groupid; " +
                  " select location_groupid,locationid,locationtype, (select concat(c.name,':',CAST(c.countryid as char),',','0,0,0') from countries c where c.countryid =g.locationid and g.locationtype=1 union " +
                  " select concat(concat(c.name,' > ',l.name),':',CAST(c.countryid as char),',',cast(l.locationid as char),',', '0,0') from countries c join locations l on l.countryid=c.countryid where l.locationid=g.locationid and g.locationtype=2 union " +
                  " select concat(concat(c.name,' > ',l.name,' > ',s.sublocation),':',CAST(c.countryid as char),',',cast(l.locationid as char),',', cast(s.sublocationid as char),',','0') from countries c join locations l on l.countryid=c.countryid join locationsub s on s.locationid=l.locationid " +
                  " where  s.sublocationid=g.locationid and g.locationtype=3 union " +
                  " select concat(concat(c.name,' > ',l.name,' > ',s.sublocation,' > ',ss.name),':',CAST(c.countryid as char),',',cast(l.locationid as char),',', cast(s.sublocationid as char),',',cast(ss.subsublocationid as char) ) from countries c join locations l on l.countryid=c.countryid  " +
                  " join locationsub s on s.locationid=l.locationid join locationsub_subs ss on ss.sublocationid=s.sublocationid where  ss.subsublocationid=g.locationid and g.locationtype=4 ) as parentids " +
                  " from location_groupdetails g where location_groupid=?groupid order by parentids asc; ";
     MySqlDataReader dr = DAO.ExecuteReader(sql, new MySqlParameter("groupid", groupId));
     DataSet ds = new DataSet();
     ds.EnforceConstraints = false;
     ds.Load(dr, LoadOption.PreserveChanges, new string[2]);
     dr.Close();
     dr.Dispose();
     return ds;
 }
开发者ID:santoshpisipati,项目名称:you-global,代码行数:18,代码来源:LocationDataProvider.cs

示例5: Load_StringsNewMerge

 public void Load_StringsNewMerge()
 {
     localSetup();
     DataSet dsLoad = new DataSet("LoadStrings");
     DataTable table1 = new DataTable("First");
     table1.Columns.Add("col1", typeof(string));
     table1.Rows.Add(new object[] { "T1Row1" });
     dsLoad.Tables.Add(table1);
     DataTable table2 = new DataTable("Second");
     table2.Columns.Add("col2", typeof(string));
     table2.Rows.Add(new object[] { "T2Row1" });
     table2.Rows.Add(new object[] { "T2Row2" });
     dsLoad.Tables.Add(table2);
     DataTableReader dtr = _ds.CreateDataReader();
     dsLoad.Load(dtr, LoadOption.OverwriteChanges, "Third", "First");
     Assert.Equal(3, dsLoad.Tables.Count);
     Assert.Equal("First", dsLoad.Tables[0].TableName);
     Assert.Equal(4, dsLoad.Tables[0].Rows.Count);
     Assert.Equal(4, dsLoad.Tables[0].Columns.Count);
     Assert.Equal("Second", dsLoad.Tables[1].TableName);
     Assert.Equal(2, dsLoad.Tables[1].Rows.Count);
     Assert.Equal(1, dsLoad.Tables[1].Columns.Count);
     Assert.Equal("Third", dsLoad.Tables[2].TableName);
     Assert.Equal(3, dsLoad.Tables[2].Rows.Count);
     Assert.Equal(2, dsLoad.Tables[2].Columns.Count);
 }
开发者ID:dotnet,项目名称:corefx,代码行数:26,代码来源:DataSetTest.cs

示例6: Load_StringsNew

 public void Load_StringsNew()
 {
     localSetup();
     DataSet dsLoad = new DataSet("LoadStrings");
     DataTable table1 = new DataTable("First");
     dsLoad.Tables.Add(table1);
     DataTable table2 = new DataTable("Second");
     dsLoad.Tables.Add(table2);
     DataTableReader dtr = _ds.CreateDataReader();
     dsLoad.Load(dtr, LoadOption.Upsert, "Third", "Fourth");
     Assert.Equal(4, dsLoad.Tables.Count);
     Assert.Equal("First", dsLoad.Tables[0].TableName);
     Assert.Equal(0, dsLoad.Tables[0].Rows.Count);
     Assert.Equal(0, dsLoad.Tables[0].Columns.Count);
     Assert.Equal("Second", dsLoad.Tables[1].TableName);
     Assert.Equal(0, dsLoad.Tables[1].Rows.Count);
     Assert.Equal(0, dsLoad.Tables[1].Columns.Count);
     Assert.Equal("Third", dsLoad.Tables[2].TableName);
     Assert.Equal(3, dsLoad.Tables[2].Rows.Count);
     Assert.Equal(2, dsLoad.Tables[2].Columns.Count);
     Assert.Equal("Fourth", dsLoad.Tables[3].TableName);
     Assert.Equal(3, dsLoad.Tables[3].Rows.Count);
     Assert.Equal(3, dsLoad.Tables[3].Columns.Count);
 }
开发者ID:dotnet,项目名称:corefx,代码行数:24,代码来源:DataSetTest.cs

示例7: Load_StringsDesc

 public void Load_StringsDesc()
 {
     localSetup();
     DataSet dsLoad = new DataSet("LoadStrings");
     DataTable table1 = new DataTable("First");
     dsLoad.Tables.Add(table1);
     DataTable table2 = new DataTable("Second");
     dsLoad.Tables.Add(table2);
     DataTableReader dtr = _ds.CreateDataReader();
     dsLoad.Load(dtr, LoadOption.PreserveChanges, "Second", "First");
     Assert.Equal(2, dsLoad.Tables.Count);
     Assert.Equal(3, dsLoad.Tables[0].Rows.Count);
     Assert.Equal(3, dsLoad.Tables[0].Columns.Count);
     Assert.Equal(3, dsLoad.Tables[1].Rows.Count);
     Assert.Equal(2, dsLoad.Tables[1].Columns.Count);
 }
开发者ID:dotnet,项目名称:corefx,代码行数:16,代码来源:DataSetTest.cs

示例8: Load_StringsAsc

 public void Load_StringsAsc()
 {
     localSetup();
     DataSet dsLoad = new DataSet("LoadStrings");
     DataTable table1 = new DataTable("First");
     dsLoad.Tables.Add(table1);
     DataTable table2 = new DataTable("Second");
     dsLoad.Tables.Add(table2);
     DataTableReader dtr = _ds.CreateDataReader();
     dsLoad.Load(dtr, LoadOption.OverwriteChanges, "First", "Second");
     CompareTables(dsLoad);
 }
开发者ID:dotnet,项目名称:corefx,代码行数:12,代码来源:DataSetTest.cs

示例9: Load_TableConflictF

 public void Load_TableConflictF()
 {
     Assert.Throws<ArgumentException>(() =>
    {
        _fillErrCounter = 0;
        _fillErr[0].init("Table1", 1, false,
            "Input string was not in a correct format.Couldn't store <mono 1> in name1 Column.  Expected type is Double.");
        localSetup();
        DataSet dsLoad = new DataSet("LoadTableConflict");
        DataTable table1 = new DataTable();
        table1.Columns.Add("name1", typeof(double));
        dsLoad.Tables.Add(table1);
        DataTable table2 = new DataTable();
        dsLoad.Tables.Add(table2);
        DataTableReader dtr = _ds.CreateDataReader();
        dsLoad.Load(dtr, LoadOption.Upsert,
                 fillErrorHandler, table1, table2);
    });
 }
开发者ID:dotnet,项目名称:corefx,代码行数:19,代码来源:DataSetTest.cs

示例10: Load_TableConflictT

 public void Load_TableConflictT()
 {
     _fillErrCounter = 0;
     _fillErr[0].init("Table1", 1, true,
         "Input string was not in a correct format.Couldn't store <mono 1> in name1 Column.  Expected type is Double.");
     _fillErr[1].init("Table1", 2, true,
         "Input string was not in a correct format.Couldn't store <mono 2> in name1 Column.  Expected type is Double.");
     _fillErr[2].init("Table1", 3, true,
         "Input string was not in a correct format.Couldn't store <mono 3> in name1 Column.  Expected type is Double.");
     localSetup();
     DataSet dsLoad = new DataSet("LoadTableConflict");
     DataTable table1 = new DataTable();
     table1.Columns.Add("name1", typeof(double));
     dsLoad.Tables.Add(table1);
     DataTable table2 = new DataTable();
     dsLoad.Tables.Add(table2);
     DataTableReader dtr = _ds.CreateDataReader();
     dsLoad.Load(dtr, LoadOption.PreserveChanges,
              fillErrorHandler, table1, table2);
 }
开发者ID:dotnet,项目名称:corefx,代码行数:20,代码来源:DataSetTest.cs

示例11: Load_TableUnknown

 public void Load_TableUnknown()
 {
     Assert.Throws<ArgumentException>(() =>
    {
        localSetup();
        DataSet dsLoad = new DataSet("LoadTableUnknown");
        DataTable table1 = new DataTable();
        dsLoad.Tables.Add(table1);
        DataTable table2 = new DataTable();
        // table2 is not added to dsLoad [dsLoad.Tables.Add (table2);]
        DataTableReader dtr = _ds.CreateDataReader();
        dsLoad.Load(dtr, LoadOption.OverwriteChanges, table1, table2);
    });
 }
开发者ID:dotnet,项目名称:corefx,代码行数:14,代码来源:DataSetTest.cs

示例12: Load_Basic

 public void Load_Basic()
 {
     localSetup();
     DataSet dsLoad = new DataSet("LoadBasic");
     DataTable table1 = new DataTable();
     dsLoad.Tables.Add(table1);
     DataTable table2 = new DataTable();
     dsLoad.Tables.Add(table2);
     DataTableReader dtr = _ds.CreateDataReader();
     dsLoad.Load(dtr, LoadOption.OverwriteChanges, table1, table2);
     CompareTables(dsLoad);
 }
开发者ID:dotnet,项目名称:corefx,代码行数:12,代码来源:DataSetTest.cs

示例13: LoadTest2

        public void LoadTest2()
        {
            DataSet ds1 = new DataSet();
            DataSet ds2 = new DataSet();
            DataTable dt1 = new DataTable("T1");
            DataTable dt2 = new DataTable("T2");
            DataTable dt3 = new DataTable("T1");
            DataTable dt4 = new DataTable("T2");
            dt1.Columns.Add("ID", typeof(int));
            dt1.Columns.Add("Name", typeof(string));
            dt2.Columns.Add("EmpNO", typeof(int));
            dt2.Columns.Add("EmpName", typeof(string));

            dt1.Rows.Add(new object[] { 1, "Andrews" });
            dt1.Rows.Add(new object[] { 2, "Mathew" });
            dt1.Rows.Add(new object[] { 3, "Jaccob" });

            dt2.Rows.Add(new object[] { 1, "Arul" });
            dt2.Rows.Add(new object[] { 2, "Jothi" });
            dt2.Rows.Add(new object[] { 3, "Murugan" });

            ds2.Tables.Add(dt1);
            ds2.Tables.Add(dt2);
            ds1.Tables.Add(dt3);
            ds1.Tables.Add(dt4);

            DataTableReader reader = ds2.CreateDataReader();
            //ds1.Load (reader, LoadOption.PreserveChanges, dt3, dt4);
            ds1.Load(reader, LoadOption.OverwriteChanges, dt3, dt4);

            Assert.Equal(ds2.Tables.Count, ds1.Tables.Count);
            int i = 0;
            foreach (DataTable dt in ds1.Tables)
            {
                DataTable dt5 = ds2.Tables[i];
                Assert.Equal(dt5.Rows.Count, dt.Rows.Count);
                int j = 0;
                DataRow row1;
                foreach (DataRow row in dt.Rows)
                {
                    row1 = dt5.Rows[j];
                    for (int k = 0; k < dt.Columns.Count; k++)
                    {
                        Assert.Equal(row1[k], row[k]);
                    }
                    j++;
                }
                i++;
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:50,代码来源:DataSetTest2.cs


注:本文中的DataSet.Load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。