|
|
#1 |
|
Frenzied Member
Join Date: Jul 06
Posts: 1,186
![]() |
read a row from database
hi, well i want to know how can i read from a datagrid view a row and show it in a richtext box???
tanks |
|
|
|
|
|
#2 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: read a row from database
Hi there,
How many rows does your dgv contain? And do you just want to read the first row? |
|
|
|
|
|
#3 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: read a row from database
I've just tested this code to a messagebox and it works
VB Code:
VB Code:
VB Code:
Hope this helps. ![]() ________________________________________________________________________ If i've helped then please rate this post!
|
|
|
|
|
|
#4 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: read a row from database
if this has solved your problem please don't forget to mark the thread [RESOLVED]!
|
|
|
|
|
|
#5 |
|
Frenzied Member
Join Date: Jul 06
Posts: 1,186
![]() |
Re: read a row from database
i think it's what i needed it. but u see what i wanna do is kind of library so when the user click on a row ex. the music title i want to show the lyrics on the rich text box. and also when he click on other music title i want to show the music lyrics of that music on richtext box so i think that i have to put this
VB Code:
Last edited by met0555; Nov 2nd, 2006 at 05:50 AM. |
|
|
|
|
|
#6 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: read a row from database
Hi, sorry about the long delay in replying.
So just to clear things up. The user will click on a row. Will this be the row header or just a cell in that row? Then you want a richtextbox to display all the text from the rest of the columns in that row? When the user clicks on another row do you want it to replace the text currently in the richtextbox or display that text in a new richtextbox? Also could you just explain to me the layout of your dgv....for example how many columns and rows it has (if known) and whether you know the names of the columns and rows or whether you need to use the index of them? If you could just give me as much detail and information as possible because i dont quite understand what exactly you need. Thanks
|
|
|
|
|
|
#7 |
|
Frenzied Member
Join Date: Jul 06
Posts: 1,186
![]() |
Re: read a row from database
ok, here it is how it will work : it's a lyrics library that i'm making it have 5 coulmn Artist, Title, Genre, Album, Lyrics . the form will be divided into two , with a datagrid and with a richtextbox and some buttons to go back... . on the datagrid view we will only see the Artist, Title Genre and Album the lyrics will be shown on the datagrid view. so when the user change the artist name the lyrics will have to match with the artist and music title name. i think i'm clear but if u need addtional info just ask me.
tanks |
|
|
|
|
|
#8 |
|
PowerPoster
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,309
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: read a row from database
If you're not already loaded your data table at form_load, it's just a mater of creating a select statement with appropriate criteria (artist name, song title...) and query the database to get the lyrics. If the lyrics is already in your data table, then just load it to the text box base on the selected row on the datagridview.
|
|
|
|
|
|
#9 |
|
Frenzied Member
Join Date: Jul 06
Posts: 1,186
![]() |
Re: read a row from database
----If the lyrics is already in your data table, then just load it to the text box base on the selected row on the datagridview. ---- i'm on this case, well, my problem is i don't know the code to retrive a specific data from the database and show it in the rich text box. the lyrics is in comlumn 5
|
|
|
|
|
|
#10 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: read a row from database
If the lyrics are already in your data table then you could use the code
VB Code:
In order to query the database you would need to use the select statement: select lyrics from tablename where artist = 'cellvalue in artist column' and title = 'cellvalue in title column' and album = 'cellvalue in album column' and then display the results in the richtextbox. You can get the values of each cell by using the same method as above but changing the column index from 5 to whatever column index is relevant. Don't forget the column indices start from 0 so the 1st column has an index of 0, the 2nd column has an index of 1 etc.... Hope this helps
Last edited by Kimmy4; Nov 3rd, 2006 at 04:18 AM. |
|
|
|
|
|
#11 |
|
Frenzied Member
Join Date: Jul 06
Posts: 1,186
![]() |
Re: read a row from database
ok, tanks, but there is something that i didn't understand. if i only put this code will it work Dim rowIndex as integer = DataGridView1.CurrentCellAddress.Y 'This will get the row index of the current selected cell
VB Code:
or i have to put the select.... ? and if i need a select statment , do i only need one or more? (The lyrics are allready stored i the database) |
|
|
|
|
|
#12 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: read a row from database
Do you actually import the lyrics to the dgv or do u need to get them from the database? and if you do import them to the dgv then are the visible?
|
|
|
|
|
|
#13 |
|
Frenzied Member
Join Date: Jul 06
Posts: 1,186
![]() |
Re: read a row from database
actualy i import it from the database
|
|
|
|
|
|
#14 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: read a row from database
so are the lyrics visible in the dgv?
|
|
|
|
|
|
#15 |
|
Frenzied Member
Join Date: Jul 06
Posts: 1,186
![]() |
Re: read a row from database
nop, they are not visible. on the datagrid view only the title ... are visible . but if we can make it visible but hide it to the user i think it will make simple the code.
|
|
|
|
|
|
#16 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: read a row from database
is there any chance you could post part of your code that imports to the dgv so i can see how you are doing it. Then i could advise you on how to do display them in the richtextbox. Because if the lyrics can be accessed without having to do a select statement then that would be easier.
|
|
|
|
|
|
#17 |
|
Frenzied Member
Join Date: Jul 06
Posts: 1,186
![]() |
Re: read a row from database
well i didn't connet yet the program with the database, but the code that i will you it the one that u gave me.
VB Code:
|
|
|
|
|
|
#18 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: read a row from database
the code i have supplied gets the values from the dgv AFTER all the information has been imported from the database. Could you post all of your code could i dont understand what you have already done so cant tell you what you need to do next. Where does all the information (ie the title, artist, album etc.) come from in the first place?
|
|
|
|
|
|
#19 |
|
Frenzied Member
Join Date: Jul 06
Posts: 1,186
![]() |
Re: read a row from database
well, i did the database with 5 column , and on the program i added the richtextbox and when i connect the database i will add the datagrid view. the title genre... will come from the database and will be show on the datagrid view. there is no big code that i put in the program form1.show me.hide...)
|
|
|
|
|
|
#20 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: read a row from database
So is there anything currently in the datagridview? Do you currently know how to connect to the database? What database do you need to connect to (are you using oracle/excel/something different to get all the information from?)?
|
|
|
|
|
|
#21 |
|
Frenzied Member
Join Date: Jul 06
Posts: 1,186
![]() |
Re: read a row from database
well ya i connect correctly, i just connected but, i was sking my self if i have to add the lyrics to the datagrid view or not. U see i want the lyrics to be view only on the richtextbox . i did it with acces 2003.
|
|
|
|
|
|
#22 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: read a row from database
OK. I think i understand now. What you can do is add the lyrics to the datagridview but then set that column's visible property to false. This way ithey will be in the dgv but the user wont be able to see them. Then you should probably create a button and call it 'Get lyrics' and inside the button place the code to get the lyrics from the dgv. This way you wont have to continually make a connection to get the lyrics because they will always be there (that just wont be apparent to the user). And because you are using a button you will only need to use the code once just make sure the user clicks on a cell in the row they require and the current row index will change accordingly. The only thing you will need to change in the code i provided above is that you will need to reference the datagridview by saying form1.datagridview1, so that it knows you are refering to that dgv.
Is this what you needed? |
|
|
|
|
|
#23 |
|
Frenzied Member
Join Date: Jul 06
Posts: 1,186
![]() |
Re: read a row from database
so finaly the code will be this
VB Code:
Last edited by met0555; Nov 3rd, 2006 at 07:40 AM. |
|
|
|
|
|
#24 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: read a row from database
No you wont need any sql code because you should have already put all the information into the dgv. You are just getting the code from the dgv instead. Just remember to put the name of the form everytime you use datagridview1 otherwise it wont know which dgv you are refering to.
|
|
|
|
|
|
#25 |
|
Frenzied Member
Join Date: Jul 06
Posts: 1,186
![]() |
Re: read a row from database
ok, tanks man
|
|
|
|
|
|
#26 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: read a row from database
Does it work?
|
|
|
|
|
|
#27 |
|
Frenzied Member
Join Date: Jul 06
Posts: 1,186
![]() |
Re: read a row from database
i'm adding data to the database, but i soon as i'm done i will let u know
|
|
|
|
|
|
#28 |
|
PowerPoster
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,309
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: read a row from database
Show me the code you use for the followings:
1. The select statement you use to get data 2. where and how you bind your datagridview to the data table Also please be clear how you want to display the lyrics... Do you want to display it when the user click on any cell in the grid or only when they actually select a row? |
|
|
|
|
|
#29 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: read a row from database
Hi stanav,
will it really matter whether they click on the cell or the row as the line VB Code:
|
|
|
|
|
|
#30 |
|
Frenzied Member
Join Date: Jul 06
Posts: 1,186
![]() |
Re: read a row from database
well i use this for searching
VB Code:
2. where and how you bind your datagridview to the data table : if u mean how i connect the dgv with the database table then : i will first connect the database then i will drag and drop it to the form. well, i want the lyrics to be viewed when a row is clicked on the dgv. the selected row artis name title .. must much with the lyrics that is going to be view on the richtextbox. |
|
|
|
|
|
#31 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: read a row from database
Have you tried the code and method that i suggested earlier yet....i'm fairly confident it will give you the results you need?
|
|
|
|
|
|
#32 |
|
Frenzied Member
Join Date: Jul 06
Posts: 1,186
![]() |
Re: read a row from database
i don't think taht i will try it son 'cuz the database will have more then 60000 data in it and to add that it will take time, and also the dtabase will be stored in my resource folder so it's betetter to add then database after i'm donw ith the datas.
|
|
|
|
|
|
#33 |
|
PowerPoster
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,309
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: read a row from database
OK... So you use "SELECT * FROM..." that means that everything is already in your data table. Now let's suppose that your table have the following fields in it: [ArtistName],[AlbumName],[SongTitle], and [SongLyrics] And you only want to show artistname, albumname, and songtitle on the datagridview. When your user click on any cell in the grid, you want to display the song lyrics on a a richtextbox for the song that is on that row. Is that correct?
|
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|