 |
|
ช่วยผมทำปุ่ม Search ผมอ่านบทความแล้วงงนะคับ VB.Net +MySQL มือใหม่ครับ |
|
 |
|
|
 |
 |
|
พี่ครับ ช่วยผมทำปุ่ม Search ทีครับ ผมอ่านแล้วไม่เข้าใจคับ
ผมใช้ VB.Net 2008 + MySQL ขอบคุญมากครับ


Code (VB.NET)
Imports MySql.Data.MySqlClient
Public Class FrmMySQL_Connection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TxtHN.Enabled = False
TxtName.Enabled = False
TxtAge.Enabled = False
BtnCancel.Enabled = False
BtnSave.Enabled = False
BtnExit.Enabled = False
BtnAddNew.Enabled = True
TextBox1.Enabled = True
End Sub
Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
TxtHN.Clear()
TxtName.Clear()
TxtAge.Clear()
TxtHN.Focus()
End Sub
Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
Try
Dim fdCon As New MySqlConnection("Database=db_social;Data Source=localhost;User Id=root;Password=")
Dim fdCom As New MySqlCommand("", fdCon)
fdCon.Open()
'-- Dim fdRead As OleDb.OleDbDataReader = fdCom.ExecuteReader(mysqlCommandBehavior.CloseConnection)
Dim sHN As String = TxtHN.Text
Dim sName As String = TxtName.Text
Dim sAge As String = TxtAge.Text
fdCom.CommandText = "INSERT INTO general (HN,Name,Age) VALUES ('" & sHN & "','" & sName & "','" & sAge & "')"
fdCom.ExecuteNonQuery()
fdCon.Close()
MsgBox("เพิ่มข้อมูล เรียบร้อยแล้ว ครับ")
BtnAddNew.Enabled = True
BtnSave.Enabled = False
BtnCancel.Enabled = False
BtnExit.Enabled = True
TxtHN.Enabled = False
TxtName.Enabled = False
TxtAge.Enabled = False
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
End
End Sub
Private Sub BtnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAddNew.Click
TxtHN.Clear()
TxtName.Clear()
TxtAge.Clear()
TxtHN.Enabled = True
TxtName.Enabled = True
TxtAge.Enabled = True
BtnCancel.Enabled = True
BtnSave.Enabled = True
BtnExit.Enabled = True
TxtHN.Focus()
End Sub
Private Sub TxtHNSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtHNSearch.TextChanged
End Sub
Private Sub BtnHNSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHNSearch.Click
End Sub
Private Sub TxtNameSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtNameSearch.TextChanged
End Sub
Private Sub BtnNameSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNameSearch.Click
End Sub
End Class
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2009-05-30 19:41:02 |
By :
purin991 |
View :
2295 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วติดปัญหาตรงไหนครับ
|
 |
 |
 |
 |
Date :
2009-05-30 21:09:13 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือ ปุ่ม ค้นหา 2ปุ่มนี้ นะครับ ไม่รู้จะใส่ โค้ดอะไรให้มันค้น หาครับ
คือ ปุ่ม BtnHNSearch ใช้ค้าหาจาก HN
ปุ่ม BthNameSearch ใช้ค้นหาจาก ชื่อ
Code (VB.NET)
Private Sub TxtHNSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtHNSearch.TextChanged
End Sub
Private Sub BtnHNSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHNSearch.Click
End Sub
Private Sub TxtNameSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtNameSearch.TextChanged
End Sub
Private Sub BtnNameSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNameSearch.Click
End Sub
|
 |
 |
 |
 |
Date :
2009-05-30 21:35:32 |
By :
purin991 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Sub BindData()
Dim objConn As New MySqlConnection
Dim objCmd As New MySqlCommand
Dim dtAdapter As New MySqlDataAdapter
Dim ds As New DataSet
Dim strConnString,strSQL As String
strConnString = "Server=localhost;User Id=root; Password=root; Database=mydatabase; Pooling=false"
strSQL = "SELECT * FROM customer WHERE (Name like '%"& strKeyWord &"%' OR Email like '%"& strKeyWord &"%') "
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
'*** BindData to GridView ***'
myGridView.DataSource = ds
myGridView.DataBind()
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
End Sub
|
 |
 |
 |
 |
Date :
2011-06-09 21:48:27 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|