Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
Dim RowArray() As String = _
{txtCode.Text, txtName.Text, "", txtQty.Text}
DataGridView1.Rows.Add(RowArray)
End Sub
วันพุธที่ 4 มีนาคม พ.ศ. 2552
Add data to datagridview
Get column names from MSSQL
-------------------------------------------------------------------------------------------------------
มันจะดึงมาทั้งดาต้าเบสเลยคับ ผมก็เอาไปปะใน Excel อีกทีแล้วค่อยกรองเอาตารางที่ต้องการแสดงผล...
SELECT table_name=sysobjects.name,
column_name=syscolumns.name,
datatype=systypes.name,
length=syscolumns.length
FROM sysobjects
JOIN syscolumns ON sysobjects.id = syscolumns.id
JOIN systypes ON syscolumns.xtype=systypes.xtype
WHERE sysobjects.xtype='U'
ORDER BY sysobjects.name,syscolumns.colid
-------------------------------------------------------------------------------------------------------
ถ้าต้องการแค่ table ใดๆ 'table_name' ใส่ชื่อตารางที่ต้องการได้เลย
SELECT * FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = 'table_name'
-------------------------------------------------------------------------------------------------------
วันอังคารที่ 3 กุมภาพันธ์ พ.ศ. 2552
Login Form VB.NET 01
Dim MyDS As New DataSet
Dim conns As String = "DataSource =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
For instance, if I were to type
x' or 1 = 1; --
in your textbox, I have just
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.NETActive Directory and VB.NET http://thaieasy2web.blogspot.com/2008/08/active-directory-and-vbnet.html
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
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
การ 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) เข้าด้วยกัน ข้ามตาราง โดยที่ไม่มีการซ้ำกันของข้อมูลในทุกๆ ตาราง
| 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
วันจันทร์ที่ 26 มกราคม พ.ศ. 2552
Getting Only the Date Part of a Date/Time Stamp in SQL Server
-----------------------------------------------------------------------------------------------
เป็นการแปลงวันที่และเวลา ตัวอย่างนี้จะเป็นการเปรียบเทียบให้เห็นสองแบบ
วิธีที่ 1 ใช้่การตัด วัน/เืดือน/ปี จาก GetDate() แล้วนำมาต่อเป็น ปี/เดือน/วัน แล้วเปลี่ยนกลับมาเป็นรูปแบบ Datetime เหมือนเดิม ซึ่งจะมีฟังค์ชันที่เกี่ยวข้องอยู่ 7 ตัว
วิธีที่ 2 ดูเรียบง่ายกว่าเพราะใช้เพียง 3 เมธอดและไม่มีการตัดข้อความแต่จะนำมาต่อให้อัตโนมัติ
ประสิทธิภาพเมื่อทดสอบกับข้อมูล 3,000 เรคอร์ด
วิธีที่ 1 : 115 ms
วิธีที่ 2: 16ms (มีประสิทธิภาพมากกว่าเยอะเลยคับพี่น้อง)
-----------------------------------------------------------------------------------------------
SELECT
-- Get the full date/time stamp as a base.
(
GETDATE()
) AS date_time_part,
-- Trying casting to a string then back to a date.
(
CAST(
(
STR( YEAR( GETDATE() ) ) + '/' +
STR( MONTH( GETDATE() ) ) + '/' +
STR( DAY( GETDATE() ) )
)
AS DATETIME
)
) AS date_only_part,
-- Try casting to float, rounding, and back to date.
(
CAST(
FLOOR( CAST( GETDATE() AS FLOAT ) )
AS DATETIME
)
) AS date_only_part2,
-- Try casting just to float to see what it looks like.
(
CAST( GETDATE() AS FLOAT )
) AS float_value,
-- Try flooring to see the intermediary step.
(
FLOOR( CAST( GETDATE() AS FLOAT ) )
) AS int_value
-----------------------------------------------------------------------------------------------
เครดิต :
http://www.bennadel.com/blog/122-Getting-Only-the-Date-Part-of-a-Date-Time-Stamp-in-SQL-Server.htm
-----------------------------------------------------------------------------------------------