2

I currently have a test database with multiple values. In this example below it is data being returned from a SELECT query.

  Barcode      Product number   Pack_size
95587056212     0100-505621     1.000000
100955870562    0100-505621     0.000000
10095587056219  0100-505621     0.000000
10095587556214  0100-505621     12.000000

What I am trying to do is trying to return values with multiple instances to different textboxes. To explain further, let's say I have one textBox and I run a query that says:

SELECT * FROM bdorf where product number = '0100-505621' 

It would return the above mentioned data in a SQL environment because there are multiple instances because there are different "Barcodes" and "Pack_Sizes" but as it relates to my Winforms c# application, am not sure how to do this. Typically that query would be ran and I would let it say return a value to a textBox but as we know it would only pull one data as it is only pointing to one textBox. To give a live scenario of what am saying. Let's say I type in the same product number as above which is "0100-505621" as used previously in my example above. Above we saw it had 3 instances but in my application below you would see it returns only one because it is only pointing to one textBox:

enter image description here

What am still figuring out is how would I make it point to multiple textBoxes regardless of the product number entered?

I had in my mind that there are a maximum of 5 possible instances as that is the data in my test database. So I was thinking of starting off with 5 textBoxes and then tying the multiple instances possible to each one and anyone that misses(having let's say 3 instances) would return 0 to those textBoxes. Am not sure if am thinking about this correctly. I welcome suggestions

AJ26
  • 501
  • 4
  • 15
  • The database has a table bdorf which contains a fixed number of columns which is the number of text boxes on you form. In most cases the database probably has a null in the column when there is no data. So after you perform your query you would need to test for null to determine which text boxes get filled. – jdweng Jul 13 '17 at 02:36
  • You can use GridView control, see this tutorial: https://www.dotnetperls.com/datagridview-tutorial – Alex Jul 13 '17 at 03:11
  • You can concatenate the strings and then add string to text field but i wont recommend that for larger data entries. Instead of this you should use grid view or table. – Faraz Sultan Jul 13 '17 at 05:17
  • @Alex I get what you are saying and have explored that already. It is possible that way but not what am looking for. I want the data that has multiple instances to go to their respective text boxes. – AJ26 Jul 13 '17 at 05:46
  • @FarazSultan I get what you are saying and have explored that already. It is possible that way but not what am looking for. I want the data that has multiple instances to go to their respective text boxes, I know there is a way to do it but I just can't wrap my head around it as to what to do. Also later down the line I would want the field to be editable. A textbox would be easier to manipulate – AJ26 Jul 13 '17 at 05:47
  • @jdweng I welcome the suggestion but that doesn't really answer my question – AJ26 Jul 13 '17 at 05:48
  • 1
    @AdamNewman - If you want the data to be displayed in a grid like fashion (it is not clear from your question) then use grid. Grid has built in functionality to edit data. – Alex Jul 13 '17 at 05:56
  • @Alex ok, I have never used grid as it relates in updating through and SQL query, is it flexible in that department? For eg. I have the numbers 1,2 and 3 in my grid and I want to update the three fields by way of a SQL query. Is it flexible in that way? – AJ26 Jul 13 '17 at 06:01
  • @Alex I just remembered that I will using inner joins multiple tables as to return corresponding values. Am not sure the grid view is flexible in that regard – AJ26 Jul 13 '17 at 06:05
  • 1
    @AdamNewman is it that you plan to use inner joins as to return data into the fields in your data up above? For example joining the product field with a similar product field with another table that also contains the description field within it? If that is the case I can see why you would rather shy away from the grid view. It would be more flexible to do it the way you are suggesting. Maybe someone can correct me if am wrong – Javy26 Jul 13 '17 at 06:10
  • 1
    @Jevon yes! that is exactly what am trying to say. Am glad someone picked that up from my post. I just want a way to return the fields to the textBoxes. Just like how I would tie one instance to one text box. Like if I get a description entitled "apple" then I would send that to the textBox. If I get apple, banana, cherry then I would be able to cast those three to those three textboxes while the other two textBoxes would remain empty. To give another example is that of pulling 4 different instances, it would then go to those 4 textBoxes and the 5th one would remain empty – AJ26 Jul 13 '17 at 06:14
  • 1
    @AdamNewman i understand. Am very much interested in this thread. I hope someone can shed some light – Javy26 Jul 13 '17 at 06:15
  • @AdamNewman am thinking about the gridview again, maybe it can work, try my solution that I will add – Javy26 Jul 13 '17 at 06:20
  • @Jevon - I still don't understand how this whole multi instance thing relates to text boxes. I am glad though that someone else did. – Alex Jul 13 '17 at 06:21
  • 1
    @Alex let me see if I can break it down. Basically what he is saying is that he wants when he enters a product number(as depicted in the screenshot) he would want the corresponding values from the database be passed to the textBoxes. For instance let's say we have a table that has the headings: `gender,amount,total` and below those columns you have the data: `male,500,340.` When you enter "male" in the field then the corresponding columns with the data beside it will then pass to the textBoxes. It's basically spitting out the corresponding values next to each other in the table – Javy26 Jul 13 '17 at 06:25

2 Answers2

1

You could try using a GridView and list all the items from the database and add some textBoxes as filters at the top and search for each respective column you would want to filter on. If you want to edit the data by way of update,insert delete then you could add some check boxes below that GridView which also has buttons labelled: "insert,update, delete" which would have the necessary queries pointing to your database on what action to take. Am not really knowledgeable on GridView but I think that could work to some extent.

Javy26
  • 375
  • 1
  • 7
  • 22
  • I understand this and thank you for the suggestion but am not working with one table, I have to tie 3 tables as to get some additional data. I was thinking of joining the data and creating an entirely different table but that is not an option as the data am working with should not be created in another table. I believe that is my current problem. The issue of having to tying three tables. Through my research I haven't seen anything feasible when it comes on to GridView and inner joins – AJ26 Jul 13 '17 at 06:32
  • 1
    @AdamNewman - RE: "tying three tables". One way (there are more than a few) is to create a View in the database that joins all the necessary tables. You can then insert , update delete this view. There are limitations: the main one is that data inserted/updated can only belong to one table. You should be able to code around it though in C# or you can create an `INSTEAD OF TRIGGER` on view. There are likely better alternatives to this in C# (I have not kept with C# developments for a few years) – Alex Jul 13 '17 at 08:03
  • See: https://stackoverflow.com/questions/7281054/sql-updatable-view-with-joined-tables regarding views. – Alex Jul 13 '17 at 08:07
1

Why not use a datagrid instead? This would have you filter multiple results. It would be particularly good because I am guessing you don't have a clear idea on how much data will be passed. So create your datagrid. Then add textboxes to edit the values of that datagrid. Because ultimately it is just database values you are really updating.

Javy26
  • 375
  • 1
  • 7
  • 22
  • 1
    I had done something similar to this. Thank you. Will mark as answer as this is the closest to my solution. – AJ26 Aug 24 '17 at 23:34