|  |  | 
          
            | คือผมใส่ Keyword ไปแล้ว กด search มันโชว์ database table นี้หมดเลยครับ แม้คำใน keyword ไม่มีคำที่หา 
 ผมอยากให้ค้นหา เฉพาะ database column Problem และเป็น keyword ที่เราพิมพ์เท่านั้นครับ
 
 รบกวนพี่ๆด้วยครับ ผมพึ่งหัด
 
 Code (VB.NET)
 
 Option Explicit On
Imports System.Data
Imports System.Data.SqlClient
Public Class WebForm1
    Inherits System.Web.UI.Page
    Dim strKeyWord As String
    Sub Page_Load(sender As Object, e As EventArgs)
        strKeyWord = Me.txtKeyWord.Text
    End Sub
    Sub BindData()
        Dim objConn As New SqlConnection
        Dim objCmd As New SqlCommand
        Dim dtAdapter As New SqlDataAdapter
        Dim ds As New DataSet
        Dim strConnString, strSQL As String
        strConnString = "Server=localhost;UID=sa;PASSWORD=;database=FMT;Max Pool Size=400;Connect Timeout=600;"
        strSQL = "SELECT * FROM masterdata WHERE (Problem 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
    Sub myGridView_RowDataBound(sender As Object, e As GridViewRowEventArgs)
        '*** NoID ***'
        Dim lblCustomerID As Label = CType(e.Row.FindControl("lblNoid"), Label)
        If Not IsNothing(lblCustomerID) Then
            lblCustomerID.Text = e.Row.DataItem("NoID")
        End If
        '*** Problem ***'
        Dim lblName As Label = CType(e.Row.FindControl("lblProblem"), Label)
        If Not IsNothing(lblName) Then
            lblName.Text = e.Row.DataItem("Problem")
        End If
        '*** Solution1 ***'
        Dim lblEmail As Label = CType(e.Row.FindControl("lblSolution1"), Label)
        If Not IsNothing(lblEmail) Then
            lblEmail.Text = e.Row.DataItem("Solution1")
        End If
        '*** Solution2 ***'
        Dim lblCountryCode As Label = CType(e.Row.FindControl("lblSolution2"), Label)
        If Not IsNothing(lblCountryCode) Then
            lblCountryCode.Text = e.Row.DataItem("Solution2")
        End If
        
    End Sub
    Sub ShowPageCommand(s As Object, e As GridViewPageEventArgs)
        myGridView.PageIndex = e.NewPageIndex
        BindData()
    End Sub
    Sub btnSearch_Click(sender As Object, e As EventArgs)
        BindData()
    End Sub
    
End Class
 
 
 Tag : .NET, Ms SQL Server 2012, Web (ASP.NET), VB.NET
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2016-07-11 11:00:38 | By :
                          akarawoot | View :
                          869 | Reply :
                          6 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |