230 likes | 448 Views
Linq to sql. Anj(^^,). Connecting to DB Displaying Data Inserting Data Updating Data Deleting Data Sample Program. contents. Connecting to db. Connecting to db (cont’d.). Right-click project Add... New Item. Connecting to db (cont’d.). Connecting to db (cont’d.).
E N D
Linq to sql Anj(^^,)
Connecting to DB Displaying Data Inserting Data Updating Data Deleting Data Sample Program contents
Connecting to db (cont’d.) Right-click project Add... New Item
Connecting to db (cont’d.) Drag and drop table/s
Right-click References Add Reference.. See highlight
Import the proper references on the .cs as necessary. See highlight
Displaying data sampleDBDataContextdb = new sampleDBDataContext(@“PATH\sampleDB.mdf"); var records = from user in db.sampleTables orderby user.ID select user; dgvRecords.DataSource = records;
Inserting data sampleDBDataContextdb = new sampleDBDataContext(@“PATH\sampleDB.mdf"); Table<sampleTable> users = db.GetTable<sampleTable>(); sampleTablenewUser = new sampleTable(); newUser.Name= txtName.Text; newUser.Username= txtUname.Text; newUser.Password = txtPassword.Text; users.InsertOnSubmit(newUser); users.Context.SubmitChanges();
Editing data sampleDBDataContextdb = new sampleDBDataContext(@“PATH\sampleDB.mdf"); var match = (from user in db.sampleTables where user.ID == rowID select user).First(); match.Name= txtName.Text; match.Username= txtUname.Text; match.Password= txtPassword.Text; users.Context.SubmitChanges();
Deleting data sampleDBDataContextdb = new sampleDBDataContext(@“PATH\sampleDB.mdf"); Table<sampleTable> users = db.GetTable<sampleTable>(); varmatch = (from user in db.sampleTables where user.ID == rowID select user).First(); users.DeleteOnSubmit(match); users.Context.SubmitChanges();
Login.cs ManageData.cs DisplayInfo.cs AddEdit.cs sample program
Login • Validate credentials • CLEAR – clears text fields • SUBMIT – submits entered data • Valid credentials – go to ManageData form • Invalid credentials – display a message box
Login (cont’d.) • Added feature • Password is not seen as the user types
managedata • DATAGRID – display and sorting of data • SEARCH – search for a specific user’s information (must be exact) • ADD – add new user • EDIT – edit existing user’s record • DELETE – delete existing user’s record upon confirmation • FILTER – realtime filter of data displayed in datagrid • X – reset filters
Managedata (cont’d.) • Added features • Full-row select on datagrid • Display specific user’s information upon double click on selected row • Enable search only when a radio button is clicked • Limit input to integers only when search option is by ID • Limit input to letters and spaces only when search option is by Name • Use same form when Add or Edit button is clicked • From date cannot be later than To date • To date cannot be earlier than From date
displayinfo • Used to display an existing user’s information
Addedit • Used to add new user or edit existing user’s information • SUBMIT – submits entered data • CLEAR – clears textboxes • CANCEL – returns to ManageData form
Addedit (Cont’d.) • Added features • Limit input to letters and spaces only on the Name textbox • Submit only when there is no blank field left