Thread: Hi
-
Feb 18th, 2012, 12:02 AM
#1
Thread Starter
New Member
Hi
I am doing a projectin VB 2008..I ave list of data being displayed in listview and it gets stored in DB..The problem is,i am unable to filter particular data based on some constraints like date,client etc..Could some1 plz help me to achieve this..How can i filter data based on various constraints..As i am new to VB,plz help me..
Thank u...
-
Feb 18th, 2012, 12:03 AM
#2
Thread Starter
New Member
Re: Hi
I am doing a project in VB 2008..I ave list of data being displayed in listview and it gets stored in DB..The problem is,i am unable to filter particular data based on some constraints like date,client etc..Could some1 plz help me to achieve this..How can i filter data based on various constraints..As i am new to VB,plz help me..
Thank u...
-
Feb 18th, 2012, 01:07 AM
#3
Re: Hi
Hi yassermsc. It's a terrible idea to not post your problem as the title of your thread. However, we are here to help you. Also, when posting a thread, it's usually best to give as much info you all ready have. Like:
- How are you populating your listbox?
- Which database(if access, what year)
- Do you have any errors?
- Do you have anything coded yet?
These are usually a standard.
Now onto the question. Depending on the info I gave above you have a couple options you can:
- Use an sql statement to filter the data
- Use the bindingsource.filter() method
If you use option 1, then it would be something like this:
Code:
SELECT * FROM datatable Where 'And then your constraints, many people use textbox = a field
If you use option 2, then it would be something like this:
Code:
bindingsource.filter = "myField = '" & TextBox1.Text & "'"
But please reply with a bit more info.
-
Feb 18th, 2012, 01:37 AM
#4
Thread Starter
New Member
Problem in listview
I am using ADODB connection in my project...I am using vb 2008 and MS access 2007.there are two forms..In the first form,i can enter data and the same form has listview where i can view,edit,delete etc...The second form only has a listview,where i can only view my data that i add in form1..Second form doesnt have anything other than a listview to view...i want to filter based on either start date or project end date or based on client or based on project name etc....
can u please tell,should i add any combo box to the second form as i want this filter only in 2nd form..and what tools should i add nd what is the code for it..
Plz help me as its very urgent..
Thank u...
-
Feb 19th, 2012, 06:14 PM
#5
Re: Hi
Assuming that you haven't opened a connection to your database yet. I would start with a simple try catch to open it. Also, Idk if you are dead set on having a list view, but I would suggest using a datagridview. That can be found in toolbox-data-datagridview. Here is what you will need to do in order to open your connection. First you have to import OLEDB, at the very top, before form1 add
Code:
Imports System.Data.Oledb
Also, simply as a good idea, turn option strict and explicit on. To do that, open your project's properties(Double Click my project in the solution explorer)
Now in your form_load event(Double Click on your form), you will open the connection. First thing, is declare any variables. In this case it will be your connection string and sql statement. Quick side note, to find the correct connection string click here.
Code:
Dim connetionString As String
Dim con As OleDbConnection
Dim sql As String
Under that you will then set those variable = to something, like such.
Code:
connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=yourdatabasename.mdb;"
con = New OleDbConnection(connetionString)
sql = "Select * from test"
Remember to have the correct connection string.
Now with the try/catch, in your try it will try to open the connection and fill your listview(I will be using a datagridview).
Code:
Try
'We need a command to populate the datagridview
Dim cmd As OleDbCommand
'Now we will open our connection
con.Open()
'We will now set that command
cmd = New OleDbCommand(sql, con)
'Here we execute that command
cmd.ExecuteNonQuery()
'Any time you open a connection it's best to close it
'When you are threw with it
con.Close()
Catch ex As Exception
'Here it will bring up a msgbox with any error we may get
MsgBox(ex.ToString)
End Try
Now try that and give us any errors you may get
-
Feb 23rd, 2012, 02:21 AM
#6
Thread Starter
New Member
Problem in listview
Thanks for suggestion.I finally got the solution with ur help..
Sorry for late reply...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|