C# Quick Reference - Sheet 3 of 4
by Gayle Laakmann, v 1.0

Calling SQL-Getting Table
DataTable datatable = new DataTable();
string q = “select * from Blogs”;
SqlDataAdapter adaptSQL = new SqlDataAdapter(q,
BlinkySQL);
adaptSQL.Fill(datatable);

foreach (DataRow drow in table.Rows)
{
   string commentbody = (string) drow["Body"];
}

Calling SQL-Getting Single Value
string q = “select max(title) from Blogs”;
SqlCommand command = new SqlCommand(q, BlinkySQL);
myCommand.Connection.Open();
string title = command.ExecuteScalar();
command.Close();

Calling SQL-Execute Non-Query
string q = “delete from Blogs”;
SqlCommand command = new SqlCommand(q, BlinkySQL);
BlinkySQL.Connection.Open();
command.ExecuteNonQuery();
BlinkySQL.Connection.Close();

Webservice
edu.upenn.cis.wren.Blinky myBlinkySvc = new
   edu.upenn.cis.wren.Blinky();

/* user exists in system */
if (myBlinkySvc.UserExists(this.textBoxName.Text))
{
   /* successfully logged in */
   if (myBlinkySvc.PasswordOK(username, password))
   {
      ...
   }
}

SQL-Insert
insert into Blogs (UserID, BlogTitle)
   values (1234, 'Yo')

SQL-Delete
delete from Blogs
   where BlogID = 37515961

SQL-Select
select UserID as 'User', max(datePosted)
   from Blogs
   where UserID <> 'Pat'
   group by UserID
Delegates
delegate void Fruitilicious(int num);
Fruitilicious yummy;

private void something()
{
   yummy = new Fruitilicious(this.Apples);
   yummy(5);
}

private void Apples(int num)
{
   ...
}

Threading
public delegate void Scruptious(string snacks);
Thread myThread;

private void startMyThread()
{
   roses = new Scruptious(this.Airport);
   ThreadStart marge = new ThreadStart(Bubbles);
   myThread= new Thread(marge);
   myThread.Start();
}

private void Airport(string word, int number)
{
   //update the UI, or do what you want.
   //This happens in the main UI thread
}

private void Bubbles()
{
   object[] parameters = {"Apples"};
   this.Invoke(this.roses, parameters);
}

private void StopMyThread()
{
   myThread.Abort();
}

SQL-Update
update Blogs
   set BlogTitle = 'hello'
   where BlogTitle like '%hi%'

Copyright © Harbor Mist, LLC 2005.  All rights reserved.

Visitors:  Hit Counter