วันอังคารที่ 3 กุมภาพันธ์ พ.ศ. 2552

Login Form VB.NET 01

Dim MyDS As New DataSet
Dim conns As String = "Data Source=ISAAC;Initial Catalog=SETH;Integrated Security=True"
Dim Conn As New SqlConnection
Conn.ConnectionString = conns

Dim Cmd As SqlDataAdapter
Cmd = New SqlDataAdapter("select * from login where username='" & Trim(C1TextBox1.Text) & "' and password='" & TRIM(C1TextBox2.Text)& "'", Conn)

Cmd.Fill(MyDS, "login")
Dim table As DataTable = MyDS.Tables("login")
Dim i As Integer
Dim j As Integer
if ( table.Rows.Count= 1)
Form1
.Show()
Me.Close()

Else
MsgBox("Incorrect Login")
C1TextBox1
.Focus()
End If

-----------------------------------------------------------------------------------------------------
As a side note:
You sql statement is susceptible to SQL
injection. Unless you are doing some sort of sanitizing on your textbox
input, you should consider using
parameters in your queries.

For instance, if I were to type
x' or 1 = 1; --
in your textbox, I have just bypassed your login procedure (because 1 = 1 will always evaluate true and thus return all rows).
You should use command parameters as demonstrated in the snippet.
-----------------------------------------------------------------------------------------------------
Dim adapter As System.Data.SqlClient.SqlDataAdapter
Dim cmd As New System.Data.SqlClient.SqlCommand("Select * from login where username = @user and password = @pass")

cmd
.Parameters.Add(New System.Data.SqlClient.SqlParameter("@user", ClTextBox1.Text.Trim()))
cmd
.Parameters.Add(New System.Data.SqlClient.SqlParameter("@pass", ClTextBox2.Text.Trim()))

adapter
= New System.Data.SqlClient.SqlDataAdapter(cmd)
-----------------------------------------------------------------------------------------------------


Login Form VB.NET 02

This code demonstrates how to retrieve the username of the current windows user in VB.NET

Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
ByRef nSize As Integer) As Integer

Public Function GetUserName() As String
Dim iReturn As Integer
Dim userName As String
userName = New String(CChar(" "), 50)
iReturn = GetUserName(userName, 50)
GetUserName = userName.Substring(0, userName.IndexOf(Chr(0)))
End Function

credit : http://www.developerfusion.com/code/4409/get-current-username-in-vbnet/

more : http://www.programmersheaven.com/mb/VBNET/372574/372574/how-to-do-username-and-password-problem-in-vbnet/?S=B20000

http://www.vb-helper.com/howto_net_password_db.html

http://www.thaiadmin.org/board/index.php?topic=75951.0;imode

อันนี่น่าสนใจดี... http://msforums.ph/forums/t/41200.aspx

Active Directory and VB.NET http://thaieasy2web.blogspot.com/2008/08/active-directory-and-vbnet.html

login login form with vb.net : how to verify ?http://www.dreamincode.net/forums/showtopic11117.htm


วันจันทร์ที่ 2 กุมภาพันธ์ พ.ศ. 2552

การประกาศตัวแปรใน Crystal Report

Variable Declarations

Before we can use a variable in a formula, it has to be declared. Basic and Crystal Syntax both have different ways of declaring variables, based on the type and scope of the variable. The most common variable declarations are included below:

Crystal Report สามารถ ประกาศตัวแปร ได้ 2 ภาษา คือ Basic และ Crystal โดยมีการเปรียบเทียบ ดังตารางข้างล่างนี้

Basic

Crystal

Dim x

n/a

Dim x ()

n/a

Dim x As Boolean

Local BooleanVar x

Dim x As Number

Local NumberVar x

Dim x As Currency

Local CurrencyVar x

Dim x As Date

Local DateVar x

Dim x As Time

Local TimeVar x

Dim x As DateTime

Local DateTimeVar x

Dim x As String

Local StringVar x

Dim x As Number Range

Local NumberVar range x

Dim x As Currency Range

Local CurrencyVar range x

Dim x As Date Range

Local DateVar range x

Dim x As Time Range

Local TimeVar range x

Dim x As DateTime Range

Local DateTimeVar range x

Dim x As String Range

Local StringVar range x

Dim x () As Boolean

Local BooleanVar array x

Dim x () As Number

Local NumberVar array x

Dim x () As Currency

Local CurrencyVar array x

Dim x () As Date

Local DateVar array x

Dim x () As Time

Local TimeVar array x

Dim x () As DateTime

Local DateTimeVar array x

Dim x () As String

Local StringVar array x

Dim x () As Number Range

Local NumberVar range array x

Dim x () As Currency Range

Local CurrencyVar range array x

Dim x () As Date Range

Local DateVar range array x

Dim x () As Time Range

Local TimeVar range array x

Dim x () As DateTime Range

Local DateTimeVar range array x

Dim x () As String Range

Local StringVar range array x

To select a scope for variables created in Basic syntax, you can use the following scope attributes in place of the Dim statement:

การเลือกใช้ตัวแปร หรือชนิดของตัวแปร จะมีข้อกำหนด หรือข้อจำกัด ของการประกาศค่า

  • Local - The variable is specific and can only be used in the formula in which it is defined. เป็นตัวแปรแบบ Local ใช้ใน Local ได้อย่างเดียว

  • Global - The variable is available to formulas throughout the entire current report. เป็นตัวแบบ Global การประกาศตัวแปรนี้ สามารถมองเห็นได้ทั้ง Report

  • Shared - The variable can be shared with a subreport as well as the entire current report. เป็นตัวแปรแบบ Shared ซึ่งส่วนมากจะให้กับ Subreport

Credit : http://theera.exteen.com/20060831/variable-declarations


การ JOIN แบบต่างๆ

SQL JOINS
SQL joins are used to query data from two or more tables, based on a relationship between certain columns in these tables.

การ join ประเภทต่างๆ เพื่อคิวรี่ข้อมูลจากตารางมากกว่า 2 ตารางขึ้นไป ขึ้นอยู่กับความสัมพันธ์ระหว่างคอลัมน์ที่ีมีอยู่ในตารางที่จะนำมา join กัน


Tables in a database are often related to each other with keys.
ตารางในฐานข้อมูลมักจะมีความสัมพันธ์กับตารางอื่นด้วย keys ของตาราง

A primary key is a column (or a combination of columns) with a unique value for each row. Each primary key value must be unique within the table. The purpose is to bind data together, across tables, without repeating all of the data in every table.
Primary Key ก็คือคอลัมน์ที่มีค่าไม่ซ้ำกันในแต่ละแถวของตารางนั้นๆ วัตถุประสงค์ก็เพื่อผูกข้อมูล(bind data) เข้าด้วยกัน ข้ามตาราง โดยที่ไม่มีการซ้ำกันของข้อมูลในทุกๆ ตาราง

Look at the "Persons" table:
P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger

Note that the "P_Id" column is the primary key in the "Persons" table. This means that no two rows can have the same P_Id. The P_Id distinguishes two persons even if they have the same name.
คอลัมน์ "P_Id" เป็น Primary Key ของตาราง "Persons" นั้นหมายความว่าจะไม่มีแถวใดๆ เลยที่มีค่าซ้ำหรือเหมือนกันกับแถวอื่น P_Id จะทำแยกระหว่างคนสองคนถึงแม้จะมีชื่อเหมือนกัน

Next, we have the "Orders" table:

O_Id OrderNo P_Id
1 77895 3
2 44678 3
3 22456 1
4 24562 1
5 34764 15

Note that the "O_Id" column is the primary key in the "Orders" table and that the "P_Id" column refers to the persons in the "Persons" table without using their names.
Notice that the relationship between the two tables above is the "P_Id" column.
คอลัมน์ "O_Id" ก็เป็น primary key ของตาราง "Orders" เช่นกันและคอลัมน์ "P_Id" นี้ก็ได้อ้างถึงบุคคลในตาราง "Persons" โดยไม่ได้ใช้ชื่อจริงๆ (แต่ใช้รหัสแทน)
จะสังเกตเห็นว่า ทั้ง 2 ตารางข้างบนนี้จะมีความสัมพันธ์กันผ่านคอลัมน์ "P_Id"


...พักก่อน เด๋วมาทำต่อนะคับพี่น้อง อดใจรอนิสนึง...










credit : http://www.w3schools.com/Sql/sql_join.asp