Skip to main content

Posts

Showing posts from January, 2011

Sample CRUD application in C# and MS SQL Server

For this example, we'll be creating a simple sales management for a ticketing office named ACheapSeat. The application allows buying of tickets for a particular event in a given venue. For this example, let's have tickets for three (3) venues: Cowboy Stadium Tickets , Ringling Brothers Circus Tickets , and Kyle Field Tickets . First, create the database named acheapseat in MS SQL Server. (I'm using MS SQL Server 2005 Express edition). Create the following tables: 1. Venues     Id: int, PK, Auto-increment, not null     Name: varchar(50), not null 2. Events     Id:int, PK, Auto-increment, not null     Description: varchar(50), not null     DateTime: timestamp, not null     VenueId: FK, int, not null     Price: numeric 3. TicketSales     Id: int, PK, Auto-increment, not null     DateBought: timestamp, not null     EventId: FK,...

How to create a Login form in C#

Create a "Windows Forms Application" project Add a new form. By default, it will have a name of "Form2" Add 2 labels, 2 textboxes, and 2 buttons like the one shown below: open the first form (Form1) and double click on the empty space. This should show the Form1_Load event. Declare an instance of Form2 and display it. (Use ShowDialog instead of Show). Open the second form (Form2) and view the properties of the second textfield (password text box). Specify * in the PasswordChar attribute.  Double click on the Login button. This will show the button1_click event. Put all necessary checking here like the one shown. **You can change the checking part to comparing the values with your database. For example: OleDbConnection cn = new OleDbConnection("YourConnectionString"); cn.Open(); DataTable dt = new DataTable(); OleDbCommand cmd = new OleDbCommand("select * from usertable where username='"+textBox1.Text+"' and password='...