How to filter datagridview from 3 textboxes?

hey, would you help me 
so, i have a form and connects to mdb database.
this is my code
Imports System.IO
Imports System.Data.OleDb
Public Class Form1
Private DBPath As String
Private conn As OleDbConnection
Private adapter As OleDbDataAdapter
Private dtMain As DataTable
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
DBPath = Application.StartupPath + "\db.mdb"
If Not File.Exists(DBPath) Then
Dim cat As New ADOX.Catalog()
cat.Create(Convert.ToString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=") & DBPath)
cat = Nothing
End If
conn = New OleDbConnection(Convert.ToString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=") & DBPath)
conn.Open()
Try
Using cmd As New OleDbCommand("CREATE TABLE [Table_1] ([id] COUNTER PRIMARY KEY, [text_column] MEMO, [int_column] INT);", conn)
cmd.ExecuteNonQuery()
End Using
Catch ex As Exception
If ex IsNot Nothing Then
ex = Nothing
End If
End Try
Using dt As DataTable = conn.GetSchema("Tables")
For i As Integer = 0 To dt.Rows.Count - 1
If dt.Rows(i).ItemArray(dt.Columns.IndexOf("TABLE_TYPE")).ToString() = "TABLE" Then
ComboBoxTables.Items.Add(dt.Rows(i).ItemArray(dt.Columns.IndexOf("TABLE_NAME")).ToString())
End If
Next
End Using
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
If ComboBoxTables.SelectedItem Is Nothing Then
Return
End If
adapter = New OleDbDataAdapter("SELECT * FROM [" + ComboBoxTables.SelectedItem.ToString() + "]", conn)
Dim builder = New OleDbCommandBuilder(adapter)
dtMain = New DataTable()
adapter.Fill(dtMain)
DataGridView1.DataSource = dtMain
End Sub
End Class
and now i have 4 textbox and 4 column table of database.
for example, this is my table :
and if i type :
textbox 1 : "1"
textbox 2 : "2"
textbox 3 : "1" then i press button2.
the result is textbox4 display : "C"
other example, if i type textbox1 : "3", textbox2 : "3", textbox3 : "2" then textbox4 diplay "J".
of course, if i type textbox1 : "3", textbox2 : "3", textbox3 : "2" then i'll get msgbox "max for column 2 is 2" or 
if i type textbox1 : "3", textbox2 : "4", textbox3 : "2" i'll get msgbox "max of column 1 is 3"
well, now im stuck, how to filter this. 
thanks before. sorry for bad english.

Hello,
The following uses Lamda and LINQ to query three text box controls where each one has a unique tag value, TextBox1.Tag = 1, TextBox2.Tag = 2, TextBox3.Tag =3. The Tag is used to dictate the order of the columns in the where condition.
In values, a where condition is used to determine any TextBox controls with Text then in the select I create a condition suitable for use in the SQL SELECT. In the variable WhereClause the conditions are combined. There is one or more conditions they are
appended to the SQL statement.
Now if we have to deal with columns of type string we need to surround them in apostrophes which opens up a can or worms if a string contains apostrophes so food for thought.
Code suitable for VS2012 or higher, for VS2010 line continuation is needed.
''' <summary>
''' Each TextBox (three of them) have their tag set to 1,2,3 for ordering columns
''' in the where clause.
''' The Where conditions are using "and", you can also do "or" instead
''' </summary>
''' <remarks></remarks>
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) _
Handles Button1.Click
Dim SelectStatement As String = "SELECT * FROM SomeTable"
Dim Values = Me.Controls.OfType(Of TextBox).Where(
Function(tb) Not String.IsNullOrWhiteSpace(tb.Text)).Select(
Function(tb)
Return New Item With
.Index = CInt(tb.Tag),
.Value = tb.Tag.ToString & " = " & tb.Text
End Function).ToList.OrderBy(Function(item) item.Index)
Dim WhereClause = String.Join(" and ",
(From T In Values Select T.Value).ToArray)
If Not String.IsNullOrWhiteSpace(WhereClause) Then
SelectStatement &= " WHERE " & WhereClause
Else
' Nothing to append
End If
Console.WriteLine(SelectStatement)
End Sub
End Class
''' <summary>
''' Strong type data in the select part of the
''' lambda statement above
''' </summary>
''' <remarks></remarks>
Public Class Item
Public Property Index As Integer
Public Property Value As String
Public Sub New()
End Sub
End Class
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

Similar Messages

  • How to filter results from 4 dynamic list menus depandant on how many of them are selected

    I have a search page with a form with 4 list menus and 1 submit that post the results to the results page. I can create a record set that either retrieves the correct data from my database if a selection is made from all four menus Or i can create the recordset if only 3 menus have a selection or the same for 2 menus and 1 menu. However i want the user to be able to make a selection from either 1, 2, 3 or all 4 of the menus and the exact data be retrieved. At present if i try to combine the recordset using AND and ORs the results are not specific enough, for example the 4 menus are Location, Type, Price & Style if a user selects from all 4 i only want to retrieve data that matches all 4 criteria, but at the same time if the user selects only 2 of the menus the i want it to retrieve data that matches specifically those 2 variables. I´m not actually sure if i should be creating a more advanced sql query of if its the php side of things that i need to look at. This is my first dynamic site so please be aware i´m still a learner where php and sql is concerned. Please can anyone help?  

    Hey there,
    Thanks for replying,
    I too am using Dreamweaver recordset, my local server is XAMPP ( apache php mysql), i´have pasted my sql recordset below to give an idea of what i´m trying to do, however this does not work as i´m trying to select the exact data based on 4 menus PRICE TYPE LOCATION and BEDS, and also want the search to work if the user only selects options from either 1, 2, 3 or 4 of the menus, with the code as it is if the user select only two options from 2 of the menus the results don´t just find (for example) all results for location AND price they find all results for the location varibale OR the price variable rather than a match for both, if you see what i mean?
    Any suggestions?  
    SELECT trueprice,`desc`, `propid`, `bathrooms`, `photo1`, locationtable.loc, typetable.style, bedtable.`number`
    FROM detailstable JOIN locationtable ON detailstable.location=locationtable.locid JOIN typetable ON detailstable.type=typetable.typeid JOIN pricetable ON detailstable.price=pricetable.priceid JOIN bedtable ON detailstable.beds=bedtable.bedid
    WHERE (location=varloc AND price = varprice AND type=vartype AND beds=varbed ) OR (price=varprice AND location=varloc AND type=vartype) OR  (price=varprice AND location=varloc AND beds=varbed) OR (price=varprice AND beds=varbed AND type=vartype) OR  ( location=varloc AND type=vartype AND beds=varbed) OR  (price=varprice AND location=varloc) OR (price=varprice AND type=vartype) OR (price=varprice AND beds=varbed) OR (type=vartype AND location=varloc) OR (type=vartype AND beds=beds) OR (location=varloc AND beds=varbed) OR (price = varprice OR beds=varbed OR type=vartype OR location=varloc)
    ORDER BY detailstable.trueprice ASC
    Look forward to receiving your thoughts,
    Linda
    Date: Wed, 21 Oct 2009 14:36:33 -0600
    From: [email protected]
    To: [email protected]
    Subject: how to filter results from 4 dynamic list menus depandant on how many of them are selected
    Hiya,
    I'm just doing my first dynamic site too, and am at a similar level to yourself.
    Can you give us more info re the site. What software, eg Dreamweaver etc are you using, and is your server using PHP or ASP etc?
    For what I've used, I amended the SQL side of things in the recordset in Dreamweaver. That way, you can test the SQL as you're setting up the recordset.
    Let me know how you're going on anyway
    Cheers
    Andy
    >

  • HOW TO FILTER DATA FROM MICROSOFT ACCESS

    HOW TO FILTER DATA FROM MICROSOFT ACCESS BASED ON DATE AND TIME AND GIVE THE RESULT TO A TABLE ?
    I need some example files , can anybody please help me ?
    Solved!
    Go to Solution.

    Just be sure to get examples specific to the Jet DBMS. It is rather "idiosyncratic" when dealing with time and date values.
    One question: the timestamp is being saved in a datetime field, right?
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • How to filter data from a source XML? Please help!

    Hi Experts,
       I have a source XML as shown below:
        <Inventory>
         <InventoryItem>
           <ItemCode>InTransit</ItemCode>
           <Quantity>1000</Quantity>
         </InventoryItem>
         <InventoryItem>
           <ItemCode>Available</ItemCode>
           <Quantity>1500</Quantity>
         </InventoryItem>
         <InventoryItem>
           <ItemCode>Restricted</ItemCode>
           <Quantity>2500</Quantity>
         </InventoryItem>
        </Inventory>
    My Target XML is as below
        <Inventory>
          <stock>1500</stock>
        </Inventory>
    The stock element contains Quantity value where ItemCode is 'Available'.
    But note that there are 3 InventoryItem nodes.
    So how to get the desired target XML in XI mapping? Basically I have to filter data from source XML based on value of an element. What is the best approach to handle this?
    Kindly help
    Thanks
    Gopal

    Hi venkat,
              Your solution does'nt work fine. But why are you using collapsecontext and splitbyvalue before putting the value into stock element?
               Kindly explain your concept.
    My target message is:
    <?xml version="1.0" encoding="UTF-8"?>
    <Inventory>
       <InventoryItem>
          <ItemCode>InTransit</ItemCode>
          <Quantity>1500</Quantity>
       </InventoryItem>
       <InventoryItem>
          <ItemCode>Available</ItemCode>
          <Quantity>1000</Quantity>
       </InventoryItem>
       <InventoryItem>
          <ItemCode>UnRestricted</ItemCode>
          <Quantity>2000</Quantity>
       </InventoryItem>
       <InventoryItem>
          <ItemCode>Available</ItemCode>
          <Quantity>2500</Quantity>
       </InventoryItem>
    </Inventory>
    I am getting the output even though stock is unbounded and I have used collapsecontext and splitbyvalue as:
    <InvStock>
      <Stock>1000</Stock>
    </InvStock>
    I should get:
    <InvStock>
      <Stock>1000</Stock>
      <Stock>2500</Stock>
    </InvStock>
    Thanks
    Gopal
    Message was edited by:
            gopalkrishna baliga

  • How to filter Choose from list object rows?

    Hi everyone,
    I'd like to show Choose from list window using SBO 2005 PL07, Actually I want to show the Active Account of G/L Account, I set the CFL object to one column as following:
    oCFLCreationParams.ObjectType = SAPbouiCOM.BoLinkedObject.lf_GLAccounts
    oCFLCreationParams.UniqueID = "CFL"
    oCFL = oCFLs.Add(oCFLCreationParams)
    Who knows how to set Choose From list object only show Active Account and do not show Title Account.
    Thanks for your help!
    Kathy

    Hi kathy
    I have not tried it on the gl accounts. But basicaly you need to add conditions to filter it. The following is an example that you would of used for business partners but only customers.
      Dim oCFLs As SAPbouiCOM.ChooseFromListCollection
                Dim oCons As SAPbouiCOM.Conditions
                Dim oCon As SAPbouiCOM.Condition
                oCFLs = oForm.ChooseFromLists
                Dim oCFL As SAPbouiCOM.ChooseFromList
                Dim oCFLCreationParams As SAPbouiCOM.ChooseFromListCreationParams
                oCFLCreationParams = SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_ChooseFromListCreationParams)
                ' Adding 2 CFL, one for the button and one for the edit text.
                oCFLCreationParams.MultiSelection = False
                oCFLCreationParams.ObjectType = "2"
                oCFLCreationParams.UniqueID = "CFL1"
                oCFL = oCFLs.Add(oCFLCreationParams)
                ' Adding Conditions to CFL1
                oCons = oCFL.GetConditions()
                oCon = oCons.Add()
                oCon.Alias = "CardType"
                oCon.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL
                oCon.CondVal = "C"
                oCFL.SetConditions(oCons)
                oCFLCreationParams.UniqueID = "CFL2"
                oCFL = oCFLs.Add(oCFLCreationParams)
    The above also compensates for the tab.
    Hope it helps

  • How to filter duplicates from XMLListCollection

    I have been trying to filter duplicates from XMLListCollection using FilterFunction.  However, it filters on the main XML tag, which happens to be the same value on all tags in this particular XML.  The values only vary in the parameters, and I need to filter the duplicates on one of them.  Is there any way to do that?

    yep, there are several ways out there
    The easy oneDo not add duplicates to the XMLListCollection
    Complicated one, extend XMLListCollection with Boolean property 'strict', override method addItemAt and trace duplicates in there.
    Super easy one is to drop XMLListCollection usage in favor of Dictionary class, it's natural capabilities will allow you to maintain strict rule for your data, just use distiction property as a key value with Dictionary class, and you are done

  • How to filter datagridview by using DatetimePicker

    Hi all I have a gridview and some data in it ,but I want to filter by date I have startTime and EndTime which are thesame, ideally I would like user to click on say 04/05/2015 items for that day shows up ,but I have been struggling with it now can get it
    to suit my purpose, find below is my Datetimepicker method Please note I am using an access DB to retrieve data.,what are my doing wrong thanks in advance?
    string strSql = String.Format("SELECT * FROM Computers WHERE StartTime >= #{0:MM/dd/yy hh:mm}# AND EndTime <=#{0:MM/dd/yy hh:mm}#", dt.ToString("MM/dd/yy hh:mm"));
    Lukaas Njie

    Is your Datagridview using a DataTable as the source.  It would be easier to filter the datatable.  Is the data a string object or a datetime object?
    You string statement should look like the following
    string strSql = String.Format("SELECT * FROM Computers WHERE StartTime >= #{0}# AND EndTime <=#{0}#", dt.ToString("MM/dd/yy hh:mm"));
    {0} is the first parameter which is already a string : dt.ToString("MM/dd/yy hh:mm")
    jdweng

  • How to filter data from two diff. table ???

    i am developing a web application with crystal reports .
    I am using crystal report api in eclipse.
    now my problem ....
    there are three tables person , natural_dead, violent_dead
    I just want to show the total no of count of person dead naturally as well as violently ., count must come from person table (as there is a flag which is set when person is dead)
    so how could i do that ??
    If you need more information , then pls let me know .
    Thanks and regards

    thanks for your reply,
    but there is one problem , i just want to show the count of dead persons caused by nature or violent  like follow
    Persons dead naturally   20
    persons dead Violently     25
         total                               45
    for this i have to use all three tables and i did that,
    but i don't know how crystal reports applying join on them ,
    As i am using crystal report's plugin in eclipse , i am doing drag n drop of tables in data field and and as per their relationship i joined them
    for your information i don't know which version of crystal report i am using , but when i use window->preferences->crystal report->crystal report application  , it showing me available version  11.8.0
    Please let me know if you need further information
    Edited by: Pankajjain15 on Jul 6, 2009 10:18 AM

  • SAP Query: How to filter records from SAP Query output before display

    Hi Friends,
      Can I delete records from an SAP query basic list before it is displayed?
    For example I want to delte all the orders whose system status is "RELEASED" before the basic list of that SAP query is displayed.
    I have gone through SAP help and found out that we can write some code in <b>END code</b> section which will execute before the basic list of the query is displayed. But I could not figure out how the code this...following is an excerpt form SAP help.
    <b>"The END-OF-SELECTION code consists of two parts (Before list output and After list output). The first part is processed before the list is output and the second part afterwards."</b>
    Can anybody help me?
    Regards,
    Bharat.
    Message was edited by:
            Bharat Reddy V

    Try this simple procedure. <b>Hope</b> this should work for you.
    You do the slection of the status in the List-Processing. say your final field of status flag is GF_STATUS.
    Immediatly after that use this within the List-Processing.
    CHECK GF_STATUS EQ '<RELEASED STATUS>'
    How it works:
    SELECT  <>       "<-------Query processing(system code).
    *< Your code put in the List processing
    CHECK GF_STATUS EQ '<RELEASED STATUS>'   "< --only released records passed.
    *>
    ENDSELECT      "<-----Query endselect(system code).
    Please let me know the result.
    Regards,
    A.Singh
    Message was edited by:
            Amarjit Singh

  • How to filter mail from an unknown ip address?

    I keep getting spam from different email addresses, and different ip addresses that have a common look and feel.  They generally are sent from some made up name, from some made up host, and have a one line description like "Save Money today, just go to this link: http://BLAH.com".  What I find is that the in the long header "received from" usually identifies "unknown" as part of the host.  I use dreamhost and they generally mark ip addresses that they don't know as 'unknown'.  Can I use this in a email filter to eliminated all received email from an unknown IP address?

    Yes, absolutely!  But this particular message not only fails the junk mail tests, but I also have spam sieve installed and it fails spam sieve.  Remember that it has a made up return path, so it's only the intermediate receiver that knows it's from an unknown IP address, I've taken out the to: and CC:
    From:                                              Enlargement pils Free trial<[email protected]>
                                             Subject:   Jamie Lynn is a bigger **** thanBritney
                                                   Date:   April 21, 2011 8:13:23 PM PDT
                                    Return-Path:   <[email protected]>
                                    Delivered-To:   [email protected]
                                           Received:   from abcf9819d8d314 (unknown [125.99.168.200])by homiemail-mx12.g.dreamhost.com (Postfix) with SMTP id 3056B2780F1; Fri, 22Apr 2011 11:53:47 -0700 (PDT)
                                           Received:   (qmail 6083 by uid 083); Fri, 22 Apr2011 11:51:32 +0800
                                      Message-Id:   <002801cc01b1$7e83d570$7b8b8050$@org>
                                  Mime-Version:   1.0
                                 Content-Type:   multipart/alternative;boundary="----=_NextPart_000_0027_01CC01B1.7E83D570"
                                            X-Mailer:   Microsoft Office Outlook 12.0
                                   Thread-Index:   AcjidAFNNjWFusN8Rk+HXMZApSrL/w==
        Content-Language:   en-us
    The Key for all of these (I get about 20 a day which fail all spam filters and junk mail filters is that the RECIEVED: says 'unknown' that's what I'd like to filter on and I can't seem to get it to work

  • How to filter data from dropdown list in sharepoint 2010

    hi,
    we have one requirement for filtering data from drop down list , we have 4 drop down  lists, in that  drop drown, we  can select any drop down that related data bind to grid view ,  

    Try using "relationshipWebURL"
    property
    Ref:
    http://spservices.codeplex.com/discussions/348401
    Another option is by using Infopath forms
    Ref:
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/9a84eae9-515f-4bef-921f-5ede5819f8df/filtering-a-cascade-dropdown-list-to-use-in-another-site
    Adnan Amin MCT, SharePoint Architect | If you find this post useful kindly please mark it as an answer :)

  • SSRS 2008 - How to filter records from the many side base an specific criteria

    I have a report that displays a summary of all the actions taken for specific project, I need to restrict those records based one of those options from the left side table.  If case 1 was
    denied it should not show in the report.  I need help with this query
    Please Help me  Angie
    Ex:
    Project name
    Actions
    Case 1
    Received
    Process
    Sent for Modifications
    Received w/Modifications
    Denied
    Case 2
    Received
    Process
    Sent for Modifications
    Received w/Modifications
    APPROVED
    Case 3
    Received
    Process
    Sent for Modifications
    Received w/Modifications
    Inactive
    Project name
    Actions
    Case 1
    Received
    Angie

    Hi,
    You can set the Rowvisibility  of the detail row to hide based on the expression
    =IIF(Fields!Actions.Value="Denied",True,False)
    Many Thanks
    Chandra
    If this Answers your issue please mark as answered.

  • WCS: How to filter alarms from trusted external AP's

    Hello,
    I have some Access Points outside of my LAN but trusted by me. I have tried to mark them in WCS as 'Known Internal' or 'Acknowledge External' but anyway I still get critcal alarms 'AP Impersonation...' (every 5 minutes) and major alarms 'AP is missing...' regarding these 'trusted' AP's.
    Is there any way to avoid these reoccuring 'false' alarms?
    Running WCS version 3.2.40 and WLC version 4.0.155.0.
    Thanks
    Kai

    Hello,
    I have some Access Points outside of my LAN but trusted by me. I have tried to mark them in WCS as 'Known Internal' or 'Acknowledge External' but anyway I still get critcal alarms 'AP Impersonation...' (every 5 minutes) and major alarms 'AP is missing...' regarding these 'trusted' AP's.
    Is there any way to avoid these reoccuring 'false' alarms?
    Running WCS version 3.2.40 and WLC version 4.0.155.0.
    Thanks
    Kai

  • How to filter emails using sender email adapter

    Hi,
    Does any one know how to filter emails of mail server using Sender email adapter(POP3 protocol ) in PI .
    To make it more clear let us assume that there are 10 emails in the email server then 3 emails should be fetched for Interface A , 3 emails Should be fetched for Interface B and remaining 4 emails should be ignored and left in the email server as it is ,  the reason for this is that it is not related with the Interface A or Interface B. Any suggestion or solution will be much appreciated.
    Thanks & Regards
    Prabhat

    Hi,
    I guess you didnt get my requirement clearly. My requirement is how to filter emails from email server using sender Email adapter in POP3 protocl and pass it to relevant Interface.
    For ex: suppose email no.1 is related to Interface A then it should go to Interface A
                   or         email no. 2 is related to Interface B then it should go to Interface B
                   or         if  email no. 3 is junk mail then it should avoid deleting that email and leave that email as it is
    The problem/challenge here is that email adapter of Interface A or B reads it first and deletes the email message so it is not available for the Interface A or B.
    So I just want that sender email adapter should filter it before deleting email from the email server.
    Can you provide some solution for this?
    Thanks & Regards
    Prabhat

  • How to filter parent & child rows from tables while export usingData export

    Hi,
    I have a requirement of export schema. Assume there is a account details table and account transactions table under schema.They have parent child relation exist. if i filter accounts from account details the corresponding transactions in account transactions table should be filterd.How to achieve this?
    Regards,
    Venkat Vadlamudi
    Mobile:9850499800

    Not sure if this is a SQL and PL/SQL question or whether it's an Oracle Apps type question or a Database General.
    Whatever, you've posted in the wrong forum (http://forums.oracle.com/forums/ann.jspa?annID=599)
    You should post in a more appropriate forum e.g.
    PL/SQL
    General Database Discussions
    etc.
    locking this thread

Maybe you are looking for

  • OIM and OIA11g Integration(error while importing Resource metadata into OIA

    Hi, I followed the below link and trying to integrate OIM 11.1.1.5 and OIA 11.1.1.3.6 And both are deployed different weblogic domains.. http://wikis.sun.com/display/OIA11gDocs/Integrating+With+Oracle+Identity+Manager,+Preferred+Method I am getting e

  • Report on MM

    Hi Gurus, I have a doubt on Grouping can anyone please help me regarding this. The issue is i displayed the vendors and many materials they are supplying like Vendor, No.of Material 100, 5 200, 11 1000, 25 and so on.................... Now i want to

  • I cant update my apps.  I just get this message.  Any help is appreciated.  To update this application, sign in to the account you used to purchase it.

    Upgraded to OX Mt Lion and the app store wants to update iMovie and iPhoto.  When I hit the update button I get this message. To update this application, sign in to the account you used to purchase it.

  • IPhone pre order

    Hi,  I plan on pre ordering the iPhone at full price. I am on a family plan, but I am not the Account Holder. I am authorized on the account, but I understand that I will have to be signed onto the account holder's account to be able to pre order. My

  • Testing EJB3.0 session beans

    Hi, recently, I spent some time to find out possible approaches to creating EJB 3.0 session bean tests. I also went over the following article http://www.oracle.com/technology/pub/articles/debu_testability_of_ejb.html. Article is referring to library