using System.Data;
using System.Data.SqlClient;
namespace RetrieveValuesDataRowArray
{
class Program
{
static void Main(string[] args)
{
string sqlConnectString = @"Data Source=Alfred-PC\SQLExpress;" +
"Integrated security=SSPI; Initial Catalog=AdventureWorks;";
string sqlSelect =
"SELECT ContactID, FirstName, LastName FROM Person.Contact " +
"WHERE ContactID BETWEEN 10 AND 13";
//create a data adapter
SqlDataAdapter da = new SqlDataAdapter(sqlSelect, sqlConnectString);
//fill a DataTable using DataAdapter
DataTable dt = new DataTable();
da.Fill(dt);
//create and fill the DataRow array
DataRow[] dra = new DataRow[dt.Rows.Count];
dt.Rows.CopyTo(dra, 0);
//access DataRow array FirstName value in row 3
//using different techniques
Console.WriteLine("FirstName = {0}", dra[2][1]);
Console.WriteLine("FirstName = {0}", dra[2]["FirstName"]);
Console.WriteLine("FirstName = {0}", dra[2]["FirstName", DataRowVersion.Default]);
Console.WriteLine("FirstName = {0}", dra[2].Field
Console.WriteLine("FirstName = {0}", dra[2].Field
Console.WriteLine("Firstname = {0}", dra[2].Field
Console.ReadKey();
}
}
}
using System;
using System.Data;
using System.Data.SqlClient;
namespace CreateStronglyTypedDataSetXsd
{
class Program
{
static void Main(string[] args)
{
string xsdFileName = @"..\..\AdventureWorks.xsd";
string sqlConnectString = @"Data Source=Alfred-PC\SQLExpress;" +
"Integrated security=SSPI; Initial Catalog=AdventureWorks;";
string sqlText = "SELECT * FROM Sales.SalesOrderHeader;" +
"SELECT * FROM Sales.SalesOrderDetail;";
//create and fill a DataSet schema using a data adapter
SqlDataAdapter da = new SqlDataAdapter(sqlText, sqlConnectString);
da.TableMappings.Add("Table", "SalesOrderHeader");
da.TableMappings.Add("Table1", "SalesOrderDetail");
DataSet ds = new DataSet("AdventureWorks");
da.FillSchema(ds, SchemaType.Mapped);
//add the data relation
ds.Relations.Add("SalesOrderHeader_SalesOrderDetail",
ds.Tables["SalesOrderHeader"].Columns["SalesOrderID"],
ds.Tables["SalesOrderDetail"].Columns["SalesOrderID"]);
//output teh XSD schema for the DataSet
ds.WriteXmlSchema(xsdFileName);
Console.WriteLine("File: {0} created.", xsdFileName);
Console.WriteLine("\n{ress any key to continue.");
Console.ReadKey();
}
}
}
No comments:
Post a Comment