PDA

View Full Version : project help


johnson6174
04-22-04, 08:00 PM
ok im writing a project that pulls from a database the problem is when i run the form and i slect from the list box nothing displays for a price. My project is suppose to pull prices from a database that i created when i select the movie for instance it isnt displaying the price of that movie from the database. is there some sort of code that I can use to pull that price when i select that movie from my listbox. also one last ? i created a back button for my form and i can't find anywhere what the code is suppose to be to make the form go to the previous form when the back button is pushed.

please please offer me some help id greatly appreciate it.

Im using VB.net to write this prog

PATH
07-07-06, 12:47 PM
hi, what u have to do is this, write a code in the selectedindexchanged of the list box.

assign the selected text to a variable, construct you sql with the value in that variable to select that particular recorf from the databas. if you get this steps right, then you are almost there.

you can use either datareader or dataset to get your data. but i think it will be ok if you can use datareader. just execute the non query. now test if the datareader has row, just select the fiels you use
to store the price in the table and assign it to another variable or the control that will contain the price on the form.

you can let me know if you have problem codding this.

take kia.

PATH
07-07-06, 01:46 PM
import System.Data
Import System.Data.SqlClient

dim myConnection as SqlConnection
dim myCommand as SqlCommand
dim myDataReader as SqlDataReader

myConnection = new SqlConnection("your connection string here")
myConnection.Open()

myCommand = new SqlCommand("your select statement here with the where clause", myConnection)

myDataReader = myCommand.ExecuteReader()

'you can now test if yor reader has row
'that is if the record is selected

if myDataReader.hasrows then

while myDataReader.read 'while the reader reads the row

'you can now assign the item to the control that will be displayed on you form

your control here = myDataReader("your field that comtain the price you want to display in the control")

'this is just to make sure that the reader does not read more than one record
'if you want to read more than one record you have to remove this line and the reader will loop all the records it read from the table

exit while

loop

end if

'dispose the command
'close the resder and the connection you opened

myCommand.dispose()
myDataReader.Close();
myConnection.Close();

PATH
07-07-06, 01:48 PM
i think this code should workout, i've tried it and it ;work


import System.Data
Import System.Data.SqlClient

dim myConnection as SqlConnection
dim myCommand as SqlCommand
dim myDataReader as SqlDataReader

myConnection = new SqlConnection("your connection string here")
myConnection.Open()

myCommand = new SqlCommand("your select statement here with the where clause", myConnection)

myDataReader = myCommand.ExecuteReader()

'you can now test if yor reader has row
'that is if the record is selected

if myDataReader.hasrows then

while myDataReader.read 'while the reader reads the row

'you can now assign the item to the control that will be displayed on you form

your control here = myDataReader("your field that comtain the price you want to display in the control")

'this is just to make sure that the reader does not read more than one record
'if you want to read more than one record you have to remove this line and the reader will loop all the records it read from the table

exit while

loop

end if

'dispose the command
'close the resder and the connection you opened

myCommand.dispose()
myDataReader.Close();
myConnection.Close();