04 November 2008

The DataReader Object

We can use a DataReader object to read data from a database. A DataReader object is effectively a forward-only collection of records from your data source.

OleDbDataReader dbReader = null;
OleDbCommand cmd = Myconnection.CreateCommand();

cmd.CommandText = "SELECT * FROM familyTree";
dbReader = cmd.ExecuteReader();


while(dbReader.Read())
{
Email = (string)dbReader.GetValue(5);
lb.Items.Add(Email);
}

map Data Access in .NET

using Datasets in .net

Creating a DataSet

Using VB.Net

Dim ds As New DataSet("DataSetName")
Console.WriteLine(ds.DataSetName)


Using C#.Net

DataSet ds = new DataSet("DataSetName");
Console.WriteLine(ds.DataSetName);


Filling the DataSet Object

Using VB.Net

Dim strConn, strSQL As String
strConn = "Provider=SQLOLEDB;Data Source=(local)NetSDK;" & _
"Initial Catalog=Northwind;Trusted_Connection=Yes;"
strSQL = "SELECT CustomerID, CompanyName, ContactName, Phone " & _
"FROM Customers"
Dim da As New OleDbDataAdapter(strSQL, strConn)
Dim ds As New DataSet()
da.Fill(ds, "Customers")


Using C#.Net

string strConn, strSQL;
strConn = "Provider=SQLOLEDB;Data Source=(local)\NetSDK;" +
"Initial Catalog=Northwind;Trusted_Connection=Yes;";
strSQL = "SELECT CustomerID, CompanyName, ContactName, Phone " +
"FROM Customers";
OleDbDataAdapter da = new OleDbDataAdapter(strSQL, strConn);
DataSet ds = new DataSet();
da.Fill(ds, "Customers");

21 July 2008

excel from sql

hm... interesting!!
i know a way to read excel from sql query.
this is how to do it...

first of all:
reconfigure 'Ad Hoc Distributed Queries' to enable position by run this query:

sp_configure 'Ad Hoc Distributed Queries', 1
reconfigure

to check or view the value of configuration run this query : "sp_configure" (find 'Ad Hoc Distributed Queries')


second:
SET IDENTITY_INSERT [table] ON 

the main formula is :
select * from OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0; Database=[FOLDER LOKASI DI SERVER]\FileExcelnya.xls', 'select * from [Sheet1$]')
attention!! the first row become the field name on sql

dont forget to
SET IDENTITY_INSERT [table] OFF


*condition: only read excel version 97-2003

18 July 2008

email in .net

Imports System.Web.Mail

#Region "Email"
Public Function SendEmail(ByVal mpSENDTO As String, Optional ByVal mpCC As String = "", Optional ByVal mpBCC As String = "", Optional ByVal mpMESSAGEFROM As String = "", Optional ByVal mpSUBJECT As String = "", Optional ByVal mpBODY As String = "", Optional ByVal mpATTACHMENT As String = "") As Boolean
Dim mlMESSAGE As New MailMessage()
Try
mlMESSAGE.To = mpSENDTO
mlMESSAGE.Cc = mpCC
mlMESSAGE.Bcc = mpBCC
mlMESSAGE.Subject = mpSUBJECT
mlMESSAGE.Body = mpBODY
mlMESSAGE.From = mpMESSAGEFROM
mlMESSAGE.BodyFormat = MailFormat.Html
SmtpMail.Send(mlMESSAGE)
Return True
Catch ex As Exception
Return False
End Try
End Function
#End Region

26 June 2008

Using data connection

use middle tier and general funtion
Dim mlMT As New MiddleTier
Dim mlGF As New GeneralFunction

Dim rsXXX As DataTable = mlMT.OpenDataTable("SELECT * FROM XXX WHERE XXX", ConfigurationManager.ConnectionStrings("YYY").ConnectionString)

(or penulisan connectionstring => "Dim mlCONNECTION As String = ConfigurationManager.ConnectionStrings("connHR").ConnectionString"
- menjadi -
Dim rsXXX As DataTable = mlMT.OpenDataTable("SELECT * FROM XXX WHERE XXX", mlCONNECTION )

fetch records:...
Dim mlABC As String = rsXXX.Rows(0).Item(0).ToString
Dim mlDEF As String = rsXXX.Rows(0).Item(1).ToString


execute query:...
mlMT.ExecuteQuery("INSERT INTO table Values('" & variable1 & "', '" & Format("mmm-dd-yyyy", variable2) & "', '" & variable3 & "', '" & variable4 & "', '" & variable5 & "'", mlCONNECTION)

04 February 2008

Top 10 New Manager Mistakes

Here is a list of the most common mistakes new managers make so you can avoid making them too.

1. Think you know everything.
If you were just promoted to Production Manager, you may feel you know everything about production. Even if that were true, and it isn't, you sure don't know everything about the most important part of your new job, managing people. Listen to the people around you. Ask for their input when appropriate. Keep an open mind.
2. Show everyone who's in charge.
Trust me, everyone in your group knows who the new manager is. You don't have to make a big show about being "the boss". You do, however, have to demonstrate that, as the boss, you are making a positive difference.
3. Change everything.
Don't re-invent the wheel. Just because the way something is done isn't the way you would do it, it isn't necessarily wrong. Learn the difference between "different" and "wrong".
4. Be afraid to do anything.
Maybe you didn't ask for the promotion. Maybe you are not sure you can do the job. Don't let that keep you from doing the job the best you can. Upper management wouldn't have put you into the job if they didn't have confidence that you could handle it.
5. Don't take time to get to know your people.
Maybe you worked alongside these people for years. That doesn't mean you know them. Learn what makes them excited, how to motivate them, what they fear or worry about. Get to know them as individuals, because that's the only way you can effectively manage them. Your people are what will make or break you in your quest to be a good manager. Give them your attention and time.
6. Don't waste time with your boss.
Since he/she just promoted you, surely he/she understands how busy you are and won't need any of your time, right? Wrong. Your job, just like it was before you became a manager, is to help your boss. Make sure to budget time to meet with him/her to both give information and to receive guidance and training.
7. Don't worry about problems or problem employees.
You can no longer avoid problems or hope they will work themselves out. When something comes up, it is your job to figure out the best solution and get it done. That doesn't mean you can't ask for other's input or assistance, but it does mean you are the person who has to see it gets taken care of.
8. Don't let yourself be human.
Just because you are the boss doesn't mean you can be human, that you can't laugh, or show emotion, or make an occassional mistake.
9. Don't protect your people.
The people in your group will be under pressure from every direction. Other departments may want to blame you for failed interfaces. Your boss may want to dump all the unpleasant jobs on your department. HR may decide the job classifications in your area are overpaid. It's your job to stand up for your people and make sure they are treated as fairly as possible. They will return the loyalty.
10. Avoid responsibility for anything.
Like it or not, as the manager you are responsible for everything that happens in your group, whether you did it, or knew about it, or not. Anything anyone in your group does, or doesn't do, reflects on you. You have to build the communications so there are no surprises, but also be prepared to shoulder the responsibility. It goes hand-in-hand with the authority.

Focus on Success

The Top Twenty List


Twenty items may seem like a lot, but I’ve actually made five short lists: one for project planning, one for applying the nine knowledge areas, one for doing, one for using stages and gates, and one for following through.

Four key planning points:

1. Do the right project. Using benefit cost analysis or ROI, and looking at opportunity cost, look at the project that gives you the biggest value for your effort and is most aligned with your company’s strategy, moving you in the direction you want to go.
2. Define scope clearly and precisely.
3. Plan the whole project. Make a plan for each of the nine areas.
4. Do good architecture. Work with words and pictures to bring people with different perspectives onto the same page, contributing to and committed to the project.

Prepare your team in just two steps:

5. Get the right team. Using the WBS, define the skills needed, and get people with those skills. Be honest about gaps, and close them by taking time to learn to get it done right.
6. Get the expertise you need. Know that being expert in one area means not being expert in other areas—sometimes closely related disciplines. Recognize that project, being unique work, require learning from and collaborating with experts. Remember, hiring experts you can work with is less expensive than not hiring experts you can work with.

Cover all the bases with the nine knowledge areas:

7. Scope. After defining scope clearly, teach the cost of changes to reduce change requests, then manage all changes, adding to the project only when it is essential.
8. Time and cost. Use unbiased, accurate estimation techniques. Set up systems to gather, track, and analyze time and cost information, so you can keep them under control
9. Quality. Focus on quality at all three levels to ensure value. At the technical level, trace requirements and design checking and testing throughout the project to reduce errors. Then design a test bed, and implement the tests. At the project level, work to prevent error, then find and eliminate the errors that slipped through. Do as much testing as you can as early as you can. Allow time for rework and retesting to ensure you’ve eliminated errors without letting new ones creep in. At the business level, include customers in testing, and remember that the goals are customer delight and added value.
10. Risk. Plan for uncertainty; prepare for the unexpected. Perform risk management with your team every week of the project.
11. Human Resources. Help each team member step up in self-management and technical expertise. Teach everyone PDCA so that they can improve. Then teach them to work together, until you have a great team of great people.
12. Procurement. Get the supplies and resources you need. If your project involves contracts, be sure to keep the contracts in alignment with project value and specifications, not just generally associated with goals and work.
13. Communications. Have a communications plan, and follow it so that you are in touch with all stakeholders throughout the project. Make sure everyone knows what they need to know to make decisions and get work done. Analyze status information to create status reports. Be prompt and decisive.
14. Integration. Constantly direct corrective action. Evaluate all events that could change the project schedule, and all scope change requests. Review the effects of any change on all nine areas before making a decision, and then implement a revised plan with rebaselining.

Keep the project on track with stages and gates:

15. Use a life cycle. At a minimum, put a gate at the beginning to clearly launch the project, and then a gate after planning, a gate after doing, and a gate after following through.
16. Every gate is a real evaluation. Bring every deliverable—parts of the product, product documentation, technical documents, the project plan and supporting documents—up to specification. If a project can’t deliver value, be willing to cancel it.

Use feedback with your team and focus on scope and quality in the doing stage:

17. Use feedback at all four levels. Teach workers to stay in lane and on schedule; ensure delivery of milestones; manage project risk; and manage project change. Watch out for continuing problems that indicate a serious planning error, such as lack of attention to one of the nine areas or a poor architectural decision.
18. Focus on scope and quality. Get it all done, and get each piece done right.

Follow through to success:

19. Deliver customer delight. Seek to exceed customer expectations while leaving customers delighted with every encounter with your team. Use every success and every error as a chance to learn to do a better job.
20. Remember ROI and lessons learned. Compare actual ROI to planned ROI, so you can be honest about the degree of your success. Compile project historical information and lessons learned to make future projects easier.


note:
This article was taken from Entrepreneur Magazine's Ultimate Guide to Project Management.

28 January 2008

No Right Click Script

No Right Click Script

Web novices often believe that by blocking their visitors use of the right mouse button that they can prevent the theft of their web page content. Nothing could be further from the truth as there are so many ways to bypass the "no right click script" that the only effects that such a script has is to annoy those of your visitors who legitimately use the context menu (as that menu is properly called) in their web navigation.

Additionally, all of the scripts that I have seen to do this only block access to the context menu from the right muse button. They don't consider the fact that the menu is also accessible from the keyboard. All anyone needs to do to access the menu using a 104 key keyboard is to select the object on the screen that they want to access the context menu for (for example by left clicking on it) and then press the context menu key on their keyboard (it's the one immediately to the left of the right CTRL key) or on a 101 key keyboard hold down the shift key and press F10 to achieve the same effect.

Well here's a really simple script that you can use to block all access to the context menu (not just from the right mouse button but from the keyboard as well) and really annoy your visitors. The script is even simpler than most of the ones that only block the mouse button and works in about as many browsers as those scripts do. Here's the entire script for you:

on body tag add this : body oncontextmenu="return false;"

Adding just that small piece of code to the body tag of your web page is more effective at blocking your visitor's access to the context menu than the many no right click scripts that you can find elsewhere on the web because it blocks access from both the mouse button and the keyboard options described above.

Of course the script doesn't work in all web browsers (eg Opera ignores it - but then Opera ignores all of the no right click scripts as well). It also does nothing to prevent your visitors from accessing the page source using the View Source option from their browser menu, from saving the web page and viewing the source of the saved copy in their favourite editor, or from using a View Source Bookmarklet.

Also, when the context menu has been disabled like this it can be easily re-enabled by typing javascript:void oncontextmenu(null) into the address bar of the browser.

11 January 2008

Access Session in Classes

In Visual Basic .NET, to access a session value:


System.Web.HttpContext.Current.Session(“MyVariable”)
System.Web.HttpContext.Current.Session(“MyVariable”).ToString()



In Visual Basic .NET, to set a session value:


System.Web.HttpContext.Current.Session(“MyVariable”) = “NewValue”

Create Connection to SQL in .NET

Public Function FetchMsSQL() As DataSet
'req namespace:
'Imports System.Data.SqlClient

Dim connString As String = "Data Source=YourServer; Initial Catalog=YourDataBase; User Id=UserInMsSQL; Password=PassInMsSQL;"
Dim sql As String = "SELECT * FROM [table]"

Dim da As New SqlDataAdapter(sql, connString)
Dim ds As New DataSet

da.Fill(ds)
da.Dispose()

Return ds

End Function


* have a nice try.... :)

09 January 2008

Data Type Length

Exact Numerics
Integers

bigint

Integer (whole number) data from -2^63 (-9223372036854775808) through 2^63-1 (9223372036854775807).

int

Integer (whole number) data from -2^31 (-2,147,483,648) through 2^31 - 1 (2,147,483,647).

smallint

Integer data from 2^15 (-32,768) through 2^15 - 1 (32,767).

tinyint

Integer data from 0 through 255.

bit

bit

Integer data with either a 1 or 0 value.

decimal and numeric

decimal

Fixed precision and scale numeric data from -10^38 +1 through 10^38 –1.

numeric

Functionally equivalent to decimal.

money and smallmoney

money

Monetary data values from -2^63 (-922,337,203,685,477.5808) through 2^63 - 1 (+922,337,203,685,477.5807), with accuracy to a ten-thousandth of a monetary unit.

smallmoney

Monetary data values from -214,748.3648 through +214,748.3647, with accuracy to a ten-thousandth of a monetary unit.

Approximate Numerics

float

Floating precision number data from -1.79E + 308 through 1.79E + 308.

real

Floating precision number data from -3.40E + 38 through 3.40E + 38.

datetime and smalldatetime

datetime

Date and time data from January 1, 1753, through December 31, 9999, with an accuracy of three-hundredths of a second, or 3.33 milliseconds.

smalldatetime

Date and time data from January 1, 1900, through June 6, 2079, with an accuracy of one minute.

Character Strings

char

Fixed-length non-Unicode character data with a maximum length of 8,000 characters.

varchar

Variable-length non-Unicode data with a maximum of 8,000 characters.

text

Variable-length non-Unicode data with a maximum length of 2^31 - 1 (2,147,483,647) characters.

Unicode Character Strings

nchar

Fixed-length Unicode data with a maximum length of 4,000 characters.

nvarchar

Variable-length Unicode data with a maximum length of 4,000 characters. sysname is a system-supplied user-defined data type that is functionally equivalent to nvarchar(128) and is used to reference database object names.

ntext

Variable-length Unicode data with a maximum length of 2^30 - 1 (1,073,741,823) characters.

Binary Strings

binary

Fixed-length binary data with a maximum length of 8,000 bytes.

varbinary

Variable-length binary data with a maximum length of 8,000 bytes.

image

Variable-length binary data with a maximum length of 2^31 - 1 (2,147,483,647) bytes.

Twiit.. Twiit... Gulp