borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (VB 2008 Express combobox & duplicate entries from access database)Next Topic (vb6 handle .net com class events) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : Search from database and store result in a listview
Poster Message
mihaispr
Level: Trainee

Registered: 19-11-2009
Posts: 1

Ads by Lake Quincy Media
icon Search from database and store result in a listview

Hi everyone and thanks for reading my post! I'm a new member on this forum and this is my first post!

I have a similar problem like here:

http://www.rajputbrotherhood.com/visual-st...ource-code.html



I have a table with the following output:




What I want to do is to perform a search:

The user types in first textbox: a number of car (NumarMasina column a value from that column).

The user selects a value from DateTimePicker (DataOraPlecare-Date Start of the car -DateTimePicker1.Value).

The user selects a value from DateTimePicker (DataOraSosire-DateArrival for the car -DateTimePicker2.Value)

Then in the last 2 textboxes (textbox2 and texbox 3 we are interested for the values of columns LocalitatePlecare(CityStart) and LocalitateSosire(CityEnd for the car).


My form looks like that:



I know that I must made a select on those 5 columns(NumarMasina,DataOraPlecare,DataOraSosire,LocalitatePlecare,LocalitateSosire) of my table FoaieParcursMasina but please suggest what I'm doing wrong in my code of the button search: (if the values contained by those 5 columns the result is added in my listview, otherwise it outputs a message don't found values to put in listview


Form1.ListView1.Items.Clear()
Dim conexiune As SqlConnection 'variabila connection with mssql
Dim comandasql As SqlCommand 'variable for query
Dim citestedate As SqlDataReader 'variable to read data
Dim msg As Integer 'variable to display message if found data or 'not

'connecting to specified servername,username and password to the 'specified database

conexiune = New SqlConnection("server=HOME-D16ABD96A8\PRIMAVERA;uid=mihaispr;pwd=mihai;database=Test")
conexiune.Open() 'open connection
comandasql = New SqlCommand("SELECT NumarMasina,DataOraPlecare,DataOraSosire,LocalitatePlecare,LocalitateSosire FROM Pers values (' " & TextBox1.Text & "', ' " &DateTimePicker1.Value&" '  ,' " &DateTimePicker2.Value&" '  ,' " &TextBox2.Text&" ', ' " & TextBox3.Text & " ')", conexiune)
comandasql.ExecuteNonQuery()
'if we are connected to the database and there are rows in tables
If conexiune = True Then
MessageBox.Show("We have found the datas" & msg)
Else 'otherwise display message don't found rows in tables
MessageBox.Show("We don't found data" & msg)
End If

conexiune.Close()



How can I correct my code hoping it's clear what I want to do. I struggle for 3 days to understand and implement my code but I don't know what I'm doing wrong.

Or is there a simpler solution as said in this tutorial?

http://www.rajputbrotherhood.com/visual-st...ource-code.html

Please suggest what I'm doing wrong or what I need to add to my code.

19-11-2009 at 09:32 AM
View Profile Send Email to User Show All Posts | Quote Reply
GeoffS
Level: VB Lord


Registered: 29-09-2004
Posts: 606
icon Re: Search from database and store result in a listview

Your "SELECT" Statement is not properly constructed. It should take the form - "SELECT Fieldname1, Fieldname2, Fieldname3 FROM Tablename WHERE (Fieldname1 = ValueToMatch) AND (Fieldname2 = ValueToMatch2)" ...
So, in your example :-
"SELECT NumarMasina, DataOraPlecare, DataOraSosire, LocalitatePlecare, LocalitateSosire FROM Pers WHERE (NumarMasina = '" & TextBox1.Text & "') AND (DataOraPlecare = " & DateTimePicker1.Value &") AND (DataOraSosire = " & DateTimePicker1.Value & ") AND (LocalitatePlecare = '" &TextBox2.Text & "') AND (LocalitateSosire = '" & TextBox3.Text & "')"


____________________________
multi-tasking - the ability to hang more than one app. at the same time.

20-11-2009 at 02:30 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB.Net : Search from database and store result in a listview
Previous Topic (VB 2008 Express combobox & duplicate entries from access database)Next Topic (vb6 handle .net com class events) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder