开发者

record search script using the SQL language in VB.NET

开发者 https://www.devze.com 2023-01-26 09:50 出处:网络
I have a slight problem on the SQL server script, this script works if I select the radio button name will be looking for a first name but if I choose the company will seek based on the company name.

I have a slight problem on the SQL server script, this script works if I select the radio button name will be looking for a first name but if I choose the company will seek based on the company name. this program for the hotel following code

enter code here
#Region "GuestList"
Sub SearchRecord()
    If TextBox1.Text = "" Then
        MsgBox("Please Insert The Key", MsgBoxStyle.Information, "Searching Record")
        TextBox1.Focus()
        Exit Sub
    End If

    Try
        If rdoname.Checked = True Then
            dtadapter = New SqlDataAdapter("select firstname as [First Name],lastname as [Last Name], address as [Address], country as [Country], company as [Company], datein as [Date In], dateout as [Date Out], note as [Note] from tcekin Where fistname = '" & TextBox1.Text & "'", connection)
        Else
            dtadapter = New SqlDataAdapter("select firstname as [First Name],lastname as [Last Name], address as [Address], country as [Country], company as [Company], datein as [Date In], dateout as [Date Out], note as [Note] from tcekin Where company = '" & TextBox1.Text & "%'", connection)
        End If

        Dim tcekin As New DataTable
        tcek开发者_高级运维in.Clear()
        dtadapter.Fill(tcekin)
        If tcekin.Rows.Count = Nothing Then
            MsgBox("Data Not Found", MsgBoxStyle.Information, "Attention")
            TextBox1.Clear()
            TextBox1.Focus()
            Exit Sub
        End If

    Catch ex As SqlException
        MsgBox(ex.Message, MsgBoxStyle.Information, "Attention")
    End Try
End Sub 
#end region

on the search button, I've called SearchRecord but it doesn't work.


Yeah, need to study up on SQL injection.

tcekin.Rows.Count = Nothing

Count returns an integer doesn't it? So, it will not equal nothing, it will equal zero if no records are returned. It's possible you're getting no records and it's not firing your message box, etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消