 |
|
 |
mihaispr Level: Trainee
 Registered: 19-11-2009 Posts: 1
|
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 |
|
|
|
|
 |
 |