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

15
  • 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. Commented Jul 13, 2017 at 5:56
  • 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 Commented Jul 13, 2017 at 6: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 Commented Jul 13, 2017 at 6:14
  • 1
    @AdamNewman i understand. Am very much interested in this thread. I hope someone can shed some light Commented Jul 13, 2017 at 6:15
  • 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 Commented Jul 13, 2017 at 6:25

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I had done something similar to this. Thank you. Will mark as answer as this is the closest to my solution.
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.

3 Comments

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
@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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.