2010-11-24 14 views
0

私はラジオボタン名を選択するとSQLサーバースクリプトにわずかな問題がありますが、このスクリプトは名前を検索するが、会社名に基づいて検索ボタン上のホテル 次のコードVB.NETでSQL言語を使用したレコード検索スクリプト

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 
     tcekin.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 

ため、このプログラムは、私がSearchRecord呼ばれてきましたが、それは動作しません。

+4

これについては、あなたは馬鹿になるでしょう。ニースSQLインジェクション... http://en.wikipedia.org/wiki/SQL_injection –

+3

コメントを+1してください。また、 "それは動作しません"ほとんど説明されていません。あなたはデバッグを試みましたか?このSearchRecordメソッド内でブレークポイントに達しましたか?どのようなエラーが出ますか? – InSane

+0

何を手に入れますか?エラーが発生したか、結果が表示されません – Wade73

答えて

0

ええ、SQLインジェクションについて勉強する必要があります。

tcekin.Rows.Count = Nothing 

Countは整数を返しますか?したがって、何も等しくない場合は、レコードが返されない場合は0になります。レコードを取得しておらず、あなたのメッセージボックスなどを発射していない可能性があります。

関連する問題