Using a DataGridView October 19, 2008
Posted by tuse in : ASP.NET, Databases, VB.NET , 4 commentsThe DataGridView Control Control can be used to display the contents of a table from the database as per an SQL query of user’s choice.
Let us see an example, add a DataGridView from the ToolBox to a new Windows Form.
When the Form Loads, we will look to fill the DGV with the following code-
Dim cmd As New Odbc.OdbcCommand("Select number as 'Book Number',title as 'Book Name', author as 'Author', publisher as 'Publisher', no_of_copies as 'No. of Copies', number_issued as 'No Issued', sub_category as 'Sub Category',edition as 'Edition' from book_details", cn)
'cn is the ODBC Connection Object defined in earlier posts
Dim adp As Odbc.OdbcDataAdapter
adp = New Odbc.OdbcDataAdapter(cmd)
Dim ds As New DataSet
adp.Fill(ds, "book_details")
Me.DataGridView1.DataSource = ds
Me.DataGridView1.DataMember = "book_details"
Me.DataGridView1.AutoResizeColumns()
We are using a DataSet-the core of the ADO.NET disconnected architecture and is used to store data in a disconnected state. In accordance to the SQL query, the DataSet is filled using the DataAdapter (adp).
The DataGridView comes with several options- enabling the user to edit records, add records, delete records.
In order to retrive data displayed in the DataGridView we can use the following code- this piece of code is very useful and I have used it on several occasions:
Dim i As Integer
i = DataGridView1.CurrentRow.Index
Dim book_number as Integer = DataGridView1.Item(0, i).Value
What we are doing in this piece of code is that we are are holding the current row’s index number in the variable i and thereafter the item in the first column in the variable book_number
Online Examination System Project in ASP.NET July 11, 2008
Posted by tuse in : ASP.NET, Databases , 122 commentsThis is a project we made in ASP.NET. Its an examination system made in Visual Studio 2008 using a MySQL database. Please do take a look at it and suggest improvements. Also, if the project is vulnerable to any security threats, please do ping us back.
I hope you will like our attempt at coding this application.
Features-
User first needs to supply valid credentials to begin the test.
Randomly chooses 5 questions from a database of 10 questions.
The test is a timed test, admin can change the duration of the test before it begins in the code.
Test-taker can leave a question un-answered and come back to the question (if time permits) using the ‘Previous’ and ‘Next’ Buttons.
Code Details-
1. Login is authenticated against a MySQL database.
2. AJAX is used for the timer, allowing only the timer label to postback to the server each second.
3. Use of the Random class to generate 5 questions out of the 10 in the database.
4. Session Management using Cookies and Session Variables.
5. Use of javascript in the master-page to prevent the ‘Back’ navigation from a page (clearing the cache) [Would love your suggestions on an alternative to this]
6. Once the 5 questions are chosen randomly, they are held in a DataTable. This is then held in a Session Variable to hold the values during postbacks.
