Friday, February 29, 2008

Database programming method

I'm talking about a method of writing a database application. You can use this method surely, because this is experience based way of programming.

The steps are:
1. Collect your User Requirement Definitions.
2. Now draw your Database Diagram. In database diagram must have all required outputs (reports).
3. You may need to draw Data Flow Diagram to make the system clear.
4. Create all forms that register data. On all command actions call an empty stored procedure that will be created later.
5. Create all program reports by using user requirement defns. Any report must be bound to exactly one database table according to Step 2.
After this 5 ways, you have an application that gets inputs, gives reports, but no processing involved. You can give it to customer to try how to work.
6. Now start writing stored procedures for main processing. It's easy. You have already named stored procedures and defined what to do in it.

My teacher said that:
Success of developing application program is based on systematic method. That's why there are many methods such as traditional system analysis, UML, RUP and so on. But if you have your way of developing programs, that is better than these standards.

I agreed it. Because i created it, suits me and my environment perfectly, no more work, can be changed freely ...

Tuesday, February 19, 2008

Oracle sequence autoincrement field and DataGrid

I needed to create a Form that does insert/edit/update/delete an Oracle table data in a DataGrid. The Oracle table has primary key that is autoincremented. I was using a trigger on before insert new row that sets sequence's nextval into primary key field. I bound DataTable to a GridControl and then inserted new row. The key value of new row in table in DBMS was correct, but GridControl's primary key field value was not updated as in DBMS. I wasted so much time to make it formally done.

My first solution was a forced one. I wrote a stored procedure that returns the sequence's next value. Called it from my C# code and set it to DataTable's primary field column. To use that i disabled the trigger.

Next to it found a Oracle 10g new feature. It's not supported in previous versions of Oracle, i heard. It's RETURNING clause. RETURNING clause is used for return values after executing a query.
For instance:

INSERT (pk_field, field1, field2, field3) INTO table1 VALUES (seq1.NEXTVAL, 'field1', 'field2', 'field3') RETURNING pk_field INTO :pk_field;

This is an example of insertQuery property of TableAdapter. Insert query itself tells that "I" insert nextval of sequence into primary key field and return it back to the grid using :pk_field parameter.

Unfortunately i couldnt get it worked. Visual Studio 2005 was not "understand" RETURNING clause, sayd me wrong SQL.

Later, a few days ago used it Visual Studio 2008. It's working. But i'm still disappointed. I need to do it in VS2005. I hope there must have any solutions. Please let me know if you have any other.

Monday, February 18, 2008

How to show large table in a data grid with .NET

I think showing large amount of data in a grid is a problem, especially for greenhorns like me. Yesterday I found a way to solve it. It doesn't use TableAdapter.Fill method and direclty shown without loading large amount of data. It will load data partially when you scroll down or filter.
To see how it works, follow this:

I tried GridControl Component of Developer eXpress Components. This GridControl control has ServerMode property.

Using ServerMode:
1. Create a new form (ex: Form1)
2. Add DataSet and typed datatable to it; Recommend you to create it using Add DataSource wizard (ex: DataSet1; CustomersDataTable)
3. Add GridControl to a Form1 (ex: GridControl1)
4. Set GridControl1.ServerMode property to True
5. Add XpServerCollectionSource control (ex: xpServerCollectionSource1)
6. Set DataSet1.CustomerDataTable to ObjectClassInfo property of xpServerCollectionSource1
you can select it from property combobox, shown as WindowsApplication1.DataSet1+CustomerDataTable
7. Select xpServerCollectionSource1 as GridControl1.DataSource
8. type following code to Form1_Load or anywhere before GridControl1 is loaded
XpoDefault.ConnectionString= DevExpress.Xpo.DB.OracleConnectionProvider.GetConnectionString("local", "scott", "tiger");
// in this case i used Oracle 10g

for other DBMS you can use other connection providers included in DevExpress.Xpo.DB package
ServerMode supports manay databases such as Oracle, MSSQL, MySQL, Access ...

You can download evalution version of the component from http://www.devexpress.com/Downloads/