|
using System;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace EmitPerfTesting
{
public partial class TestBed : Form
{
public TestBed()
{
InitializeComponent();
}
public static void Main()
{
Application.Run(new TestBed());
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind;Data Source=Conwell");
con.Open();
SqlDataAdapter adp = new SqlDataAdapter("select * from Customers", con);
DataSet ds = new DataSet();
adp.Fill(ds);
con.Close();
DataTable dt = ds.Tables[0];
//Moment of truth!
IDataRowAdapter dra = DataRowAdapterFactory.CreateDataRowAdapter(dt);
StringBuilder text = new StringBuilder();
foreach (DataRow row in dt.Rows)
{
text.Append(row[dra.GetOrdinal("CustomerID")].ToString()).Append(", ");
text.Append(row[dra.GetOrdinal("CompanyName")].ToString()).Append(", ");
text.Append(row[dra.GetOrdinal("ContactName")].ToString()).Append(", ");
text.Append(row[dra.GetOrdinal("ContactTitle")].ToString()).Append(", ");
text.Append(row[dra.GetOrdinal("Address")].ToString()).Append(", ");
text.Append(row[dra.GetOrdinal("City")].ToString()).Append(", ");
text.Append(row[dra.GetOrdinal("Region")].ToString()).Append(", ");
text.Append(row[dra.GetOrdinal("PostalCode")].ToString()).Append(", ");
text.Append(row[dra.GetOrdinal("Country")].ToString()).Append(", ");
text.Append(row[dra.GetOrdinal("Phone")].ToString()).Append(", ");
text.Append(row[dra.GetOrdinal("Fax")].ToString()).Append(", ");
text.Append(Environment.NewLine);
}
textBox1.Text = text.ToString();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I have been a professional developer since 1996. My experience comes from many different industries; Data Mining Software, Consulting, E-Commerce, Wholesale Operations, Clinical Software, Insurance, Energy.
I started programming in the military, trying to find better ways to analyze database data, eventually automating my entire job. Later, in college, I automated my way out of another job. This gave me the great idea to switch majors to the only thing that seemed natural…Programming!