Progress Monitor for IdealProgrammer.com
Take Swift, Intelligent, Massive, Planned, Loving, Effective (S.I.M.P.L.E.) Action to Transform Self into Ideal
Skip Repetitive Navigational Links
Home
News
Presenters
Register
Contact
Categories
Titles
Converter
Code Samples
C# ASP.NET
C# Console
HTML
JavaScript
SQL Server
VB ASP.NET
VB Console
Please login
C# Select Statement Source Code Example
Description:
Illustrates using Sql Select in C# to write Output Table.
Example Class Main:
using System; using System.Data; using System.Data.SqlClient; public class clsSqlSelect { static SqlConnection con; public void Main() { con = new SqlConnection("Server=(local)\\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI"); // Create the command object string str = "SELECT EmployeeID, FirstName, LastName FROM Employees"; SqlCommand cmd = new SqlCommand(str, con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "Employees"); //DataColumn dc; foreach ( DataColumn dc in ds.Tables[0].Columns) { Console.Write("{0,15}", dc.ColumnName); } Console.Write("\n"); //DataRow dr; foreach ( DataRow dr in ds.Tables[0].Rows) { int i; for (i = 1; i < = ds.Tables[0].Columns.Count; i++) { Console.Write("{0,15}", dr[i - 1]); } Console.Write("\n"); } Console.ReadLine(); } }
Example Class Program:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CSharp_Syntax { class Program { static void Main(string[] args) { //DatabaseADONET clsSqlSelect mySqlSelect = new clsSqlSelect(); mySqlSelect.Main(); } } }
Home
News
Presenters
Register
Contact
Categories
Titles
Converter
Code Samples
C# ASP.NET
C# Console
HTML
JavaScript
SQL Server
VB ASP.NET
VB Console