Having data post to a multi-line textbox from a datagridview query???!!!

Status
Not open for further replies.

drew4663

Well-known member
Joined
May 3, 2007
Messages
62
Programming Experience
1-3
SETUP:
I have 1 database, 1 table and a few columns. I have setup a datagridview to allow for me to filter, by date, the records I want shown. (Example: search all records for 04/23/12 and it will return every record that contains that date.)

ISSUE:
When I press the search button and it displays two columns of info based on my search I want the data, no matter how many records there are, to be copied & pasted to a multi-line textbox of just one column.

Example:
When the form loads it fills the datagridview with all records
sopID(primary) | DATE | CASE NUMBER
1 04/21/12 17102652
2 04/23/12 17104852
3 04/23/12 17102264
4 04/25/12 17126854

Then, I enter search of 04/23/12 and press find and it returns
sopID(primary) | DATE | CASE NUMBER
2 04/23/12 17104852
3 04/23/12 17102264

All of this is working correctly. What I then want in the mulitline textbox is just the case number.

17104852
17102264


I have been able to send only the selected cell so far but I want it to be auto and multiple. As soon as they hit find I want the data to populate in the grid for verification and the result to populate a multiline textbox to the right on the same form.
Any help with this would be greatly appreciated.
 
How exactly are you filtering? Are you setting the Filter property of a BindingSource or something else?

I select the tableadapter and added the query...

VB.NET:
SELECT        sopID, Date, CaseNumber
FROM            SOP_FORM
WHERE        (Date LIKE ? + '%')
 
If you already filled the grid with all the data to begin with, why are you then discarding all of that and then getting some of the same data again? Why not just filter what you already have?

Also, why are you using LIKE with dates? That suggests that you are storing dates in a database as text, which is criminal. Dates should be stored as dates.
 
The end result is this. After the data is filtered the data is then supposed to go to a multiline textbox and the user will push another button to send the text in the textbox as an email. To be honest, not sure why, but I have always had bad luck with using dates as dates. I am such a novice at this that I probably do a lot of things backwards. This is just a personal app for me and not something that is going to be in anyone else's hands. Any clue on how I can get the data from the gridview to the textbox so I can send it as the message body of an email?
 
It's not bad luck. It's just that you did things the wrong way. Maybe now would be a good time to learn to do things the right way.

I would also strongly suggest changing the way you're doing the filtering. There's nothing wrong with using a query to retrieve filtered data but not when you already have all the data to start with.

Whether you do that or not, if you've used the Data Source wizard and dragged a table onto your form then you have a BindingSource. You should loop through the items in that, which will be DataRowViews, and get the appropriate field value from each one. You can combine those field values into a single String and then display that in the RTB.
 
I appreciate your help and you have helped me many times before but I'm just not understanding what you are saying. Not that you are saying something wrong. I'm just not comprehending the words/terms. I'm either making something easy harder than it is or I am taking something really difficult and underestimating it. Either way, thank you and hopefully I can come up with the solution of getting filtered data sent via email with the click of a button. :)
 
If you have never heard of a loop then you need to stop what you're doing right now. Loops are one of the fundamental building blocks of pretty much every programming language so they should be one of the absolute first things you learn about. There's no way that you should be working with databases if you can't write a loop. I suggest that you find yourself a good beginners tutorial and work through the fundamentals in a logical order. This is a good one:

Microsoft Visual Basic .NET tutorials for Beginners
 
Querying a database is the same no matter what you intend to do with the data. If you want to do something with the result set other than bind it to your control(s) then you're going to have to use a loop of some sort, so my advice is to learn about loops first.
 
I was able to do what I needed to do and without involving loops. Now my program works for me the way it was intended to. Remember this one day and try to find the correlation and message. I feel as if I called up a mechanic and asked him where the oil filter was on my new unfamiliar foreign car and he responded with telling me that I first needed to read about how engines work! I'm not saying that understanding loops was hard or needing to know them in general isn't a good idea. What I am saying is that sometimes people just want to change their oil. They're not wanting to become a mechanic but are wanting to save money by doing as much for themselves as possible......as possible.

I needed an answer to my problem. I needed this program to work for me. I don't have the money to hire a programmer. I don't want to become a programmer. I can see someone wanting to me to learn it on my own if this was my career or something I was in school for and this was a project but it wasn't. End rant.
 
First up, learning to write loops in VB is not comparable to learning how engines work. It's more like learning how the pedals work while driving, i.e. fundamental to the task at hand. As for the solution, I'd be interested to see how it was done because I'm not aware of any method to move data from a DataTable or DataGridView into a TextBox in .NET 2.0 that would not involve a loop.
 
I knew your argument would lead down that path. It's not about the task.....it's about fulfilling a request. I asked a question seeking an answer to allow me to get this program working and completed. It was my last task. You decided to not provide me with an answer because you were trying to go the more, in your mind, educator route. Teach a man to fish or give him one dilemma. I'm filtering the data by date, I am choosing to use datagridview1.selectall and then I am using the most simple getclipboardcontent and then clipboard.gettext. The program works as I intended it to and has now made my shift easier at work to process cases. I'm a happy camper.
 
Status
Not open for further replies.
Back
Top