Lecture 06
Lecture 06
April
p 11,, 2008 • Project Phase 1
1 2
• Dataset: DataTable,
DataTable DataRow
DataRo • Can access a database
• Connecting to a database – Complex, but you should see the predecessors !
http://www.ecma-international.org/activities/Languages/Introduction%20to%20Csharp.pdf
3 4
1
Properties: Getters and Setters
Hello World
public class Point {
private int x; Point uvw = new Point();
using
i System;
S t
private string c;
uvw.position = 55;
class Hello { public int position { uvw.color = “green”;
static void Main() { get { return x; } uvw.position =
Console.WriteLine("Hello world"); set { x = value; c = “red”; } uvw.position * 2;
} } if (uvw.color == “green”)
} public string color { …
get { return c; }
set { c = value; x++; }
5 6
}
Indexers Enum
publicGetters
class Stuff { with […]
and setters
private
i int
i x[];[]
enum Color: byte {
public int this[int i] { Red = 1,
get {x[2*i+1]=0; return x[2*i]; } Green = 2,
set { x[2*i] = value; x[2*i+1]=1; } Blue = 4,
} Black = 00,
Stuff uvw = new Stuff(); White = Red | Green | Blue,
}
uvw[12] = 55;
uvw[99] = uvw[12]*7 + 2;7 8
2
Partial Classes The DataSet Class
• Some fields defined in file 1 This is an important class that allows you to
• Other fields defined in file 2 interact with a database
3
Connecting to a Database Phase 1
//* create inside a table called “books”
books *// • Task 1: Schema design
SqlConnection c = new SqlConnection( . . . “name” . . .);
• Task 2: Import sample data
string q = “select title, price year SQL = a string !!!
from products “impedance
p
where price < 100”; mismatch” • Task 3: Modify
Modif starter code
4
Task 1: Schema Design Task 1: Schema Design
What you should do: Things to worry about:
• Read description AND look inside the • Keys/foreign keys: note table order matters!
starter code App_code/Provided/… • Make sure you represent all the data
• Read the classes, determine the fields… • Null-able or not (don’t worry too much)
Things not to worry
orr about:
abo t:
• fname or FirstName or PersonFirstName ?
• varchar(20) or char(200) or varchar(120) ?
17 18
19 20
5
Task 3: Modify Starter Code Task 3: Modify Starter Code
/* your GetInvoices code goes here */
• What you have to do: Substitutes
string s = String.Format( id for {0}
• App_Code/Phase1/Billing and Shipping/…
@“SELECT …
Public partial class Customer { FROM ….
WHERE x.customerId = {0} …”, id); Defined in
/* add your own fields, like: */
Provided
private int id,
id
StoreContext store = StoreContext.current;
Procedure List<invoice> GetInvoices() { DataSet ds = new DataSet( );
/* your GetInvoices code goes here */ DataTable invoices = store.GetDataTable(s, ds, “invoices”);
} 21
/* continued on next slide…. */ 22
6
Time Estimate
• Task
as 1:: about 9 tables
tab es or
o so
– 2 hours or more
• Task 3:
– Need to find out WHAT to modify in starter code
– May need to DROP TABLEs then go to Task 1
– Total time here: anywhere from 2 to 14
25