Results 1 to 18 of 18

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

  1. #1
    drew4663 is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2007
    Posts
    62
    Reputation
    96

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

    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.

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,081
    Reputation
    1651
    How exactly are you filtering? Are you setting the Filter property of a BindingSource or something else?

  3. #3
    drew4663 is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2007
    Posts
    62
    Reputation
    96
    Quote Originally Posted by jmcilhinney View Post
    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...

    Code:
    SELECT        sopID, Date, CaseNumber
    FROM            SOP_FORM
    WHERE        (Date LIKE ? + '%')

  4. #4
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,081
    Reputation
    1651
    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.

  5. #5
    drew4663 is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2007
    Posts
    62
    Reputation
    96
    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?

  6. #6
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,081
    Reputation
    1651
    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.

  7. #7
    drew4663 is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2007
    Posts
    62
    Reputation
    96
    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.

  8. #8
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,081
    Reputation
    1651
    Do you know how to execute a loop? Do you have a BindingSource?

  9. #9
    drew4663 is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2007
    Posts
    62
    Reputation
    96
    Quote Originally Posted by jmcilhinney View Post
    Do you know how to execute a loop? Do you have a BindingSource?
    I'm afraid I have not used or even heard of a loop. I do have a binding source. SOP_FORMBindingSource

  10. #10
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,081
    Reputation
    1651
    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

  11. #11
    drew4663 is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2007
    Posts
    62
    Reputation
    96
    How about this.....I would like to send a query from the database to a richtextbox. Any hints?

  12. #12
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,081
    Reputation
    1651
    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.

  13. #13
    drew4663 is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2007
    Posts
    62
    Reputation
    96
    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.

  14. #14
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,081
    Reputation
    1651
    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.

  15. #15
    drew4663 is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2007
    Posts
    62
    Reputation
    96
    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.

  16. #16
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,081
    Reputation
    1651
    I can honestly say that I never would have thought of that because it's a filthy hack. If it works and you're happy with a filthy hack then that's fine but you probably ought to mention when you ask a question that you have no interest in good programming practices because anyone who assumes that you are would never suggest such a solution. You're going to find a lot of people try to get you to do things the right way and it will wind up being a big waste of your time and theirs.

  17. #17
    drew4663 is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    May 2007
    Posts
    62
    Reputation
    96
    Don't be mad at me because I found the solution and you couldn't!

  18. #18
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,081
    Reputation
    1651
    Quote Originally Posted by drew4663 View Post
    Don't be mad at me because I found the solution and you couldn't!
    I'm no madder at you for that than a mechanic would be at someone who used a pair of stockings instead of a fan belt, but if you want to make me mad then you should continue with the childish taunts. I'm saying that, for your benefit, you should let people know in future that all you care about is the end result and not the manner in which it's achieved. You seem displeased that I tried to get you to spend time learning how to program so, to avoid such displeasure in the future, you should let people know that you don't want to learn how to program.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking