Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. ADO.NET Question

ADO.NET Question

Scheduled Pinned Locked Moved Database
questioncsharphelp
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    ghost181
    wrote on last edited by
    #1

    May i know what is the problem in my code below? Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try If TextBox1.Text <> "" Then Dslogin1.Clear() OleDbDataAdapter1.SelectCommand.CommandText = _ "SELECT * FROM Login WHERE username = " & TextBox1.Text & "" OleDbDataAdapter1.Fill(Dslogin1, "Login") DataGrid1.SetDataBinding(Dslogin1,"Login") End If Catch e1 As Exception MessageBox.Show(e1.ToString) End Try End Sub i cant search the username from the textbox1.

    M C 2 Replies Last reply
    0
    • G ghost181

      May i know what is the problem in my code below? Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try If TextBox1.Text <> "" Then Dslogin1.Clear() OleDbDataAdapter1.SelectCommand.CommandText = _ "SELECT * FROM Login WHERE username = " & TextBox1.Text & "" OleDbDataAdapter1.Fill(Dslogin1, "Login") DataGrid1.SetDataBinding(Dslogin1,"Login") End If Catch e1 As Exception MessageBox.Show(e1.ToString) End Try End Sub i cant search the username from the textbox1.

      M Offline
      M Offline
      Mairaaj Khan
      wrote on last edited by
      #2

      ghost181 wrote:

      OleDbDataAdapter1.SelectCommand.CommandText = _ "SELECT * FROM Login WHERE username = " & TextBox1.Text & ""

      Include Quotation marks: OleDbDataAdapter1.SelectCommand.CommandText = _ "SELECT * FROM Login WHERE username = '" & TextBox1.Text & "'"

      _____________________________ Success is not something to wait for, its something to work for.

      1 Reply Last reply
      0
      • G ghost181

        May i know what is the problem in my code below? Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try If TextBox1.Text <> "" Then Dslogin1.Clear() OleDbDataAdapter1.SelectCommand.CommandText = _ "SELECT * FROM Login WHERE username = " & TextBox1.Text & "" OleDbDataAdapter1.Fill(Dslogin1, "Login") DataGrid1.SetDataBinding(Dslogin1,"Login") End If Catch e1 As Exception MessageBox.Show(e1.ToString) End Try End Sub i cant search the username from the textbox1.

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        Ignore the last response because he doesn't actually solve your real problem. Your real problem is the code is susceptable to a SQL Injection Attack. You should use parameterised queries. e.g.

        OleDbDataAdapter1.SelectCommand.CommandText =
        "SELECT * FROM Login WHERE username = ?";
        OleDbDataAdapter1.SelectCommand.Parameters.Add("", TextBox1.Text);

        This will go some way to protecting your database from attack. You will want to read SQL Injection Attacks and Tips on How to Prevent Them[^] which tells you what a SQL Injection Attack is, how to spot code that is susceptable and how to correct the problem.


        Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

        G S 2 Replies Last reply
        0
        • C Colin Angus Mackay

          Ignore the last response because he doesn't actually solve your real problem. Your real problem is the code is susceptable to a SQL Injection Attack. You should use parameterised queries. e.g.

          OleDbDataAdapter1.SelectCommand.CommandText =
          "SELECT * FROM Login WHERE username = ?";
          OleDbDataAdapter1.SelectCommand.Parameters.Add("", TextBox1.Text);

          This will go some way to protecting your database from attack. You will want to read SQL Injection Attacks and Tips on How to Prevent Them[^] which tells you what a SQL Injection Attack is, how to spot code that is susceptable and how to correct the problem.


          Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

          G Offline
          G Offline
          ghost181
          wrote on last edited by
          #4

          Thanks Colin Angus Mackay, i solve the problem already.:)

          1 Reply Last reply
          0
          • C Colin Angus Mackay

            Ignore the last response because he doesn't actually solve your real problem. Your real problem is the code is susceptable to a SQL Injection Attack. You should use parameterised queries. e.g.

            OleDbDataAdapter1.SelectCommand.CommandText =
            "SELECT * FROM Login WHERE username = ?";
            OleDbDataAdapter1.SelectCommand.Parameters.Add("", TextBox1.Text);

            This will go some way to protecting your database from attack. You will want to read SQL Injection Attacks and Tips on How to Prevent Them[^] which tells you what a SQL Injection Attack is, how to spot code that is susceptable and how to correct the problem.


            Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

            S Offline
            S Offline
            S Douglas
            wrote on last edited by
            #5

            Colin Angus Mackay wrote:

            SQL Injection Attacks and Tips on How to Prevent Them[^] which tells you what a SQL Injection Attack is, how to spot code that is susceptable and how to correct the problem.

            As often as that article is referenced why not just include it in your sig? :)


            I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:

            C 1 Reply Last reply
            0
            • S S Douglas

              Colin Angus Mackay wrote:

              SQL Injection Attacks and Tips on How to Prevent Them[^] which tells you what a SQL Injection Attack is, how to spot code that is susceptable and how to correct the problem.

              As often as that article is referenced why not just include it in your sig? :)


              I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              S Douglas wrote:

              As often as that article is referenced why not just include it in your sig?

              I don't currently have room. :) I'll consider it when space frees up a bit.


              Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups