Sunday, February 3, 2008

An easy way to manipulate database using Subsonic

I had been using various tools to manipulate database. The only tool that i find very simple so far .net web development is subsonic. http://www.subsonicproject.com/.

Subsonic is really powerful to CRUD your database. SQL is not nessary and it is all object oriented. The best object realtional mapper for .net 2.0

Give a try :)

Thursday, January 17, 2008

dropdownlist postback problem ASP.NET

have you encounter that ASP.NET dropdownlist control have a problem of persistent the data in the items list after you had make a postback? The problem is actually you have disabled the EnableViewState. Therefore the control will not persist any data after an postback. To enable it back, just - EnableViewState="true".

This is a super tips, because you might disabled it, in this case turn it on!

Thursday, November 29, 2007

Export table and data using SqlBulkCopy

i have one database to be exported and i try to use the import and export features from the sqlserver 2005. However i enconter one problem which is the primary key of the enabled indentity insert is all mess up after the importing to my new database. I just found and tested a utility and it works quite well.


method to export

generate a sql script with having the sql schema
use this program simple sql bulk copy downloadable from http://projects.c3o.com/files/default.aspx


ref:

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx

Sunday, October 14, 2007

What programming language is the best?

Every programmer will ask this very common question What programming language is the best? C#? Java? C++? C? Perl? or ...??? In order to answer this question, you have to ask yourself what programming language you like most. Next, think about does the language powerful enough to be used in the type of application your are doing. Finally, some language is designed specifically and targeted to certain type of application. If the type of application you are doing match the language you are using, development productivity will improve and it is more easier to program. Likewise, you will get crazy in the middle of development if you choose the wrong language. For me, I want simple and powerfully high level language... I believe C# and it is my only choice.

Tuesday, August 14, 2007

Create a serch engine with linq

I always amazed by how search engine works and it seem so wonderful that google has created the most amazing search engine to put infomation on our finger tips. Would you like to create a simple search engine? Here you can do it pretty easy with Linq.

The techniques needed in constructing search engine are regular expression, Linq, Generic, C#, sort and ranking algorithm.

Here is the code:


using System;
using System.Collections.Generic;
using
System.Text;
using System.Text.RegularExpressions;
using
System.Query;
namespace search
{
public class Search
{
private
List _SearchRelevance = new
List();
public List
SearchRelevence
{
get
{
return
_SearchRelevance;
}
}
private List _Results =
new List();
public List
Results
{
get
{
return
_Results;
}
}


public Search(string input, string[]
text)
{
for (int i = 0; i < text.Length; i++)
{
SearchRelevance
sr = new SearchRelevance(input,
text[i]);
sr.Calculate();
_SearchRelevance.Add(sr);
}
Sort();
}
private
void Sort()
{
var relevences =
from w in _SearchRelevance
orderby
w.RelevancePoint descending
select w;
foreach (SearchRelevance sri in
relevences)
{
_Results.Add(sri);
}
}

}
public class
SearchRelevance
{
public SearchRelevance(string input, string
text)
{
_OriginalText = text;
_UserInput = input;
}
public
override string ToString()
{
return _RelevancePoint.ToString() +" "+
_OriginalText ;
}
internal void Calculate()
{
string[] splitedinput
= UserInput.Split(new char[] { ' ' });
Dictionary
relevency = new Dictionary();
//initialize the relevency
dic.
for (int i = 0; i < splitedinput.Length;
i++)
{
relevency.Add(splitedinput[i], 0);
}
for (int i = 0; i <
splitedinput.Length; i++)
{
Regex reg = new Regex(splitedinput[i],
RegexOptions.IgnoreCase);
if (reg.IsMatch(OriginalText))
{
int
point;
relevency.TryGetValue(splitedinput[i], out
point);
relevency.Remove(splitedinput[i]);
relevency.Add(splitedinput[i],
++point);
}
}
_Relevancy = relevency;
//sum the relevency
int
rpoint = 0;
foreach (KeyValuePair kv in
relevency)
{
rpoint += kv.Value;
}
_RelevancePoint =
rpoint;
}
private string _UserInput;
public string
UserInput
{
get
{
return _UserInput;
}
}
private string
_OriginalText;
public string OriginalText
{
get
{
return
_OriginalText;
}
}
private int _RelevancePoint;
public int
RelevancePoint
{
get
{
return _RelevancePoint;
}
}
private
Dictionary _Relevancy = new Dictionaryint>();
public Dictionary
Relevancy
{
get
{
return _Relevancy;
}
}
}
public class
Program
{
static void Main(string[] args)
{
string[] sb = new
string[4];
sb[0] = "Relevance cassida shell theory may be seen as an
attempt";
sb[1] = "registered by NSF (Class H1) cassida for use
where";
sb[2] = "Shell Cassida Silicone Fluid is";
sb[3] = "to work out in
detail one of Grice’s central claims";
string input = "nsf shell central h1
sillicone fluid";
Search sr = new Search(input, sb);
SearchRelevance[] res
= sr.Results.ToArray();
}
}
}

Thursday, August 9, 2007

XML as data storage, query with Linq

Most of the time data is stored as database but how about data stored as a file format? If data is stored as file format meaning that we have much more power to decide the storage however file as storage is not always the ideal situation if data is too complex to store and difficute to manage. Today we see relational database is so successfull because of the database management design. We use SQL to manipulate data and we are happy with the power and the flexibility that SQL could give.

However, there is a problem that storing data in database always seem to be bulky for small application. Imagine that, you are creating a subsystem as a service of a larger system, which has is own database implementation. Logically, it is not advisable that the sub system use it own database or share the data store with the larger system mainly because having a it own database is too bulky and has environment limitation. And, if data store is shared meaning that integration will be too costly and complicated.

The solution is to use XML as isolated data storage. We have to build services around the data and expose it as interface for larger system integration. Having using xml as data, the integration is much simpler and less impact on the overall larger system.

Most people i would say do not like to query XML data because of the complicated query and it is not SQL liked. However, now the situation has changed, you can query data having SQL liked by using linq to XML. Developer can use linq to query XML data. In the next discussion, I will show you how you can play around with this Linq to XML technique.

Frackyly, i do not like XML as data store until i found that Linq has so much to promise.

for more information on the linq technology, please visit
http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx

Read XML data and bind to datagridview .NET

if you want to bind xml data to your datagrid, you need do as below:

dataSet1.ReadXml("kwyProducts.xml");
dataGridView1.DataSource =
dataSet1;
dataGridView1.DataMember = "KWYProducts";

Notes: please specify your DataMember correctly else will throw you this error:

Child list for field KWYProduscts cannot be created.