พอดีผมลอง Run แบบขึ้น Host แล้วขึ้นError ครับว่า...
ด่านล่างนี่คือ Code ครับ เป็น VB
Code (VB.NET)
Imports System.Management
Imports System.Data
Imports System.Data.SqlClient
Public Class hwidmanager
Public Function GetCpuId() As String
Dim CpuInfo As String = String.Empty
Dim Temp As String = String.Empty
Dim mc As ManagementClass = New ManagementClass("Win32_Processor")
Dim moc As ManagementObjectCollection = mc.GetInstances()
For Each mo As ManagementObject In moc
If CpuInfo = String.Empty Then
CpuInfo = mo.Properties("ProcessorId").Value.ToString
Button2.Enabled = True
End If
Next
Return CpuInfo
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = "" Then
MsgBox("ขออภัย กรุณาใส่เลข HWID ก่อน")
Else
Dim Thread = New Threading.Thread(AddressOf Me.addhwid)
Thread.SetApartmentState(Threading.ApartmentState.STA) 'Single Thread Apartment
Thread.Start()
Label2.Text = "รอสักครู่ กำลังเพิ่ม HWID.."
End If
End Sub
Private Sub addhwid()
If TextBox1.Text = "" Then
MsgBox("ขออภัย กรุณาใส่เลข HWID ก่อน")
Else
Dim strConnString As String
Dim conn As SqlConnection
'เชื่อมต่อ conn ไปฐานข้อมูล
'(conn = New SqlConnection)
'ตัวอย่าง
'conn.ConnectionString = "server=127.0.0.1; user id=root; password=123456; database=hwid; charset=utf8;"
strConnString = "Data Source=localhost\SQL2005;Initial Catalog=pm2you_com_pm2you;Persist Security Info=True;User ID=xxxxxx;Password=xxxxxx;Max Pool size=20000"
' ใช้ได้'รอใช้ 'strConnString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\pm2you.mdf;Integrated Security=True;User Instance=True"
conn = New SqlConnection(strConnString)
conn.Open()
Try
Catch myerror As Exception
MsgBox("ไม่สามารถเชื่อมต่อฐานข้อมูลได้")
End Try
'sql query
Dim myAdapter As New SqlDataAdapter
Dim sqlquery = "SELECT * FROM pm2you WHERE pm2you_Hwid1 = '" + TextBox1.Text + "'"
Dim myCommand As New SqlCommand()
myCommand.Connection = conn
myCommand.CommandText = sqlquery
' start query
myAdapter.SelectCommand = myCommand
Dim myData As SqlDataReader
myData = myCommand.ExecuteReader()
'see if user exits
If myData.HasRows = 0 Then
conn.Close()
conn.Open()
Dim registerfinal As New SqlDataAdapter
' ตัวอย่าง
' sqlquery = "INSERT INTO table_hwid (hwid) VALUES ('" + TextBox1.Text + "')"
sqlquery = "INSERT INTO pm2you (pm2you_Hwid1) VALUES ('" + TextBox1.Text + "')"
myCommand.Connection = conn
myCommand.CommandText = sqlquery
'start query
registerfinal.SelectCommand = myCommand
myData = myCommand.ExecuteReader
MsgBox("เพิ่มหมายเลข HWID ลงในฐานข้อมูลแล้ว", MsgBoxStyle.Information, "สำเร็จ")
Else
MsgBox("ขออภัย มี HWID อยู่ในระบบแล้ว", MsgBoxStyle.Critical, "ขออภัย")
End If
End If
End Sub
End Class