I am a beginner at C #, and I feel a little scared to get data from the data bank. Although I was a little scared, I still tried to learn it! Today, I made a small program to export data from data sources to the console.
Using System. Data. sqlclient;
Static Void Main ( String [] ARGs)
{
# Region Connected data centers
Sqlconnection dataconnection = New Sqlconnection ();
String Username = " SA " ;
String Password = " Sh2_123 " ;
Dataconnection. connectionstring = " User ID = " + Username + " ; Password = " + Password + " ; Initial catalog = northwind; " + " Data Source = ccm02 \ sqlexpress " ;
Dataconnection. open ();
# Endregion
# Region Begin row sentence
Sqlcommand datacommand = New Sqlcommand ();
Datacommand. Connection = Dataconnection;
Datacommand. commandtext = " Select orderid, orderdate, shippeddate, shipname, shipaddress, shipcity, shipcountry from orders where customerid = 'blonp' " ;
Sqldatareader datareader = Datacommand. executereader ();
# Endregion
# Region Obtain information
While (Datareader. Read ())
{
# Region Define the change to the nearest bit
Int Orderid = Datareader. getint32 ( 0 );
Datetime orderdate = Datareader. getdatetime ( 1 );
Datetime shipdate = Datareader. getdatetime ( 2 );
String Shipname = Datareader. getstring ( 3 );
String Shipaddress = Datareader. getstring ( 4 );
String Shipcity = Datareader. getstring ( 5 );
String Shipcountry = Datareader. getstring ( 6 );
# Endregion
Console. writeline (
" Order {0} \ n placed {1} \ n shipped {2} \ n " +
" To address {3} \ n {4} \ n {5} \ n {6} \ n " ,
Orderid, orderdate, shipdate, shipname, shipaddress, shipcity, shipcountry );
}
# Endregion
}