none
how i check if the value input in textbox is in a field in dataset RRS feed

  • General discussion

  • hy,i search an idea,to compare input value in textbox, and compare it if existe in query ..

    my part of code is bellow:

    OleDbDataAdapter adp = new OleDbDataAdapter("select field from table ", connection);
                    DataSet ds = new DataSet();
                    adp.Fill(ds);



                    if (  '" + Textbox.Text + "' == ds1.Tables[0].Rows[0][0].ToString()))  //compare the input txt in textbox with values in   dataset

    it seem the query give a rows,if possible compare textbox with value in rows

                   
    Thursday, June 9, 2016 6:35 PM

All replies

  • If you just want to know if there is any record in table that has field [SomeField] = the value from the text box [Textbox], then the quickest way is to execute a simple query that has a WHERE clause that specifies that criterian, and see if it returns any rows.  If you specify a TOP 1 clause, it should even minimize the amount of traffic across the network.  So the query might be something like:

        sqlString = "SELECT TOP 1 [SomeField] FROM [SomeTable] WHERE [SomeField] = '" + Textbox.Text + "'";

    That assumes that the field is a text field, and that it won't contain the single-quote character (').

    Note, though, that concatenating in the value of a text box, presumably filled by user input, leaves you open to a SQL injection attack.  It would be better to use a parameterized query, but the exact method of doing that depends on your programming platform.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Thursday, June 9, 2016 7:51 PM
  • i have done a query with where ..but not work

    i create a dataset in table to get field:select field from table

    but when i fill textbox, i need to compare the value of textbox with record,if not existe ,show messagebox no value found in table like value in textbox!!!

    i found this

    if(ds.Tables[0].DefaultView.RowFilter = "textbox1.text as idea ,it search all record form field


    • Edited by foxnight Thursday, June 9, 2016 11:46 PM
    Thursday, June 9, 2016 11:43 PM
  • i have done a query with where ..but not work


    I suggest you give the details of what you tried with a query before, showing the code and telling what results you got.  So far, I think a simple query is the best solution, and if it didn't work, you must have made a mistake in your implementation.

    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Tuesday, June 14, 2016 10:34 PM