Efficiently showing Access data in C# - c#

I've been learning about obtaining and modifying access data in C# for a few days and I have a pretty good idea on how to do it.
What I find a bit hard to understand is how to efficiently show data in A windows form.
My access table is information on a Supplier, and it has 11 fields in it (name, street etc)
Now I want to be able to have users see all this data as well as modify it in C#.
So far I have tried just having 11 text boxes with corresponding list boxes as well, and the list boxes contained a specific field and when you clicked on any of them, all the data would go into the text box which could be modified.
However I found that this is ridiculously inefficient as I was changing the value of listboxes/Textboxes constantly.
is there a way to efficiently show all the data in a Table? (even if it has many fields, IE upwards of 15), or should I look at an alternative solution.
Thank you.

Use the DataGridView control.
Read C# DataGridView tutorial.

Related

Is a database or a file more suitable to store varying user input and then retrieve values to find average or sum?

This is a stand alone application, and the data doesn't need to be saved for a later time, and data will not be shared between users, it's for one user to input their data and carry out an assessment, the user can then note down the results, but none of this needs to be stored into the app for a later time.
It's a 2 stage assessment, the first stage requires the user to fill out a number of forms with structural details of columns, depending on how many columns they have, and the second stage needs to sum some of those column values and some will need to be averaged, to then display the final values of the assessment, onto a final form.
Only numbers are entered into each form, and results will also be in the form of numbers which are then displayed on a graph. There are around 30 text boxes of user input, which are input into a input form that pops of from a button from the parent form, stage one of the assessment is then carried out for each column on each parent form. Each parent form renderred onto a new tab using this EasyTabs solution Creating a C# Application with Chrome-Style Tabs using EasyTabs in WinForms - YouTube[^] that I found online.
I'm an absolute beginner on C# , so I couldn't figure out how I would take a value from each form and display the sum or average onto the final form, if I don't know how many forms there will be for each user during run time, as each user will have a different amount, I was thinking it's maybe some sort of loop during run time, but I'm just not sure what that would look like.
After speaking to a friend, they recommended a single form, with a save and refresh button, where the data gets saved onto a file, and then gets retrieved would be better, but there are say 10 different user input values that need to be picked up from each form, and then averaged or summed, I started learning about StreamReader and StreamWriter and how files work in C#, but it was really difficult to figure out how to lay out the data in the file, how to get C# to sum the correct values together etc etc.
What would be the best way to approach this problem?
Thank you for your help.
If by "Form" you mean the WinForms definition of Form (Basically a new window), then I advise you to have a look at this post describing how to get data from one Form to the other.
To make a TextBox only accept numbers, you can use the a regular expression validation ^[0-9]*$ if you want to allow empty inputs or ^[0-9]+$ if you want at least one digit. if you want to allow negative numbers as well it is ^(\+|-)?[0-9]$. Note: all those will allow leading zeroes. For decimals you need to allow periods as well. ^(\+|-)?[0-9]*(\.[0-9]+)?$. Read up on regular expressions if you need anythin else. This website can help you design and test them.
To get a number from your text box you need to parse the text in the textbox. dotNet has plenty of functions for that already. For example Int32.TryParse() or if you want it to throw an exception Int32.Parse(). Others are similar. Have a look at the MSDN documentation to see how to use them.
As for averaging: Making a database, connecting to it and then using it to calculate the average of a number does seem like a pretty roundabout way of doing things. In programming you tell the computer what to do. So if someone told you to calculate an average, would you write the numbers in a book an then send them off to someone to calculate for you? Surely not.
You can just add all the numbers together in your code and divide by the amount of numbers. But there is an even easier solution. Add all your numbers to a List<int> and call it's .Sum() method and then divide by the return of it's .Count() method.
Saving the data to a file is only needed if you want to shut off the program between the user inputs or want to document the inputs.
Writing and reading numbers from a file is fairly straight forward though. Have a look at these tutorials provided by Microsoft: Write to file, Read from file, Read file one line at a Time. Writing to files uses the exact same methods as System.Console, just that you use a file stream instead of StdIO.
As for data layouts, there are several sane variants. For something simple you can just make your own (i.e. the position in the file dictates where the data goes, or each data point comes with a descriptor before it, for example inputA: 24). For more complex data, I would consider creating a class for your data and then serialize the data, for example using the popular Newtonsoft JSON library or XML and don't worry about how the file is structured.

Create and store database locally with asp.net

I have a small website with couple different forms inserting data to sql. But the users have problem with it. The problem is that they seem to be going through them too fast that its not recording everything.
So i am trying to see if there was a way to store all the data locally and have it insert to sql at the end when they are done filling out forms. Is this possible?
For example:
I have a form that have 5 fields but 2 are auto populated and 1 entered manually and 2 are being inserted using bar code scanner. The bar code scanner is the last value required before being inserted, so i was hoping there was a way to insert that into locally store access database (not seen by anyone) and when they press "Finish" all that data from access will be inserted into sql.
Hope i painted the picture clear enough.
Let me know any and all possibilities.
EDIT: Here is the aspx and .cs, hope this helps. Yes i realize that i have validation for the bar code, but not sure why its slow. And i may have stuff cluttered. So please bear with me.
Sounds like you need to put that data in application session or cache and then flush the data to db.
Here are some other choices though:
Flat files (simply serialize your objects, use protobuf)
Use Embeded Db: SqlLite, VistaDb, Sql Server Compact...
Store data in the browser via localstorage (dom storage, this is html 5 feature)

Create a report with its respective chart from a chosen LINQ query in C#

I'm quite busy reading different posts over how to create reports from dynamic queries. I have the next problem and maybe someone here can help me with this:
I have a class where I can create a dataGridView from a dynamic dataTable in a project made with C# from VS 2010. I populate my DataTable with one of 9 different linq queries that I have according to the user requirements, which also are saved in a register in my database. Starting from this point, I need to make a report where I can show of the same way the data selected.
I have found the code from the website got ReportViewer and it works quite good. Only I have a last problem. I need my report to show a chart according to the parameters passed via the DataTable. I saw the examples that they have there for the charts but they work quite restrict with what I need, and the code for the chart generator that is incluided in the Dynamic Table project is quite extense and a bit complex for a beginner like me.
Do you know any other examples that maybe I can find to use to make the code in my project? Many thanks in advance :).
I found another way to do it:
Now I'm using classes as datasources and filling arrays of these classes with the contect of the datatable.
I pass these arrays as my datasources for the project.
I group my data by the number of fields I want to display and then I choose between pre made .rdlc files where I show my data to the user.

How do I query Oracle and store the results into a DataGrid?

I'm an amateur in C#.NET programming.
I need to populate a grid with data from a table I've created based on the "date (date type)" given by the user from a date picker put in a textbox. There is a submit button which populates the grid using the date.
I need to know how to connect to the database and the grid and how to populate it with the date given in the textbox. I do not know anything about grid views.
I couldn't find a relevant site in google for my problem. I'll be more than happy if someone could provide with a general code or a link regarding my problem.
Thanks in advance :)
This involves understanding a few different technologies. I don't think you'll find a single source for all of this. Since this is a general question, I'll give you general guidance.
Oracle
To connect to Oracle, you'll want to use Oracle's DataAccess component (ODAC). Read a few of the API examples that comes with the ODAC to learn how to connect to the database and execute commands. It is very similar to ADO.NET.
When extracting information from the database as the result of a query, you'll want to load the database data into a local .NET class object. This is what you will feed your data grid.
WPF/Winforms
How you bind your results to the DataGrid will depend on whether or not you are using WPF vs Winforms. If you are using WPF, you will want to research ItemsSource binding and the INotifyPropertyChanged interface. Essentially, you'll store a list (typically an ObservableCollection<T>) of your result entities and bind the DataGrid's ItemSource property to the list. You'll then define what columns you want to display in the grid and how those map to the properties of the database entity.
I'm not as familiar with the Winforms grids, but I believe there is a way to bind to those as well.

How would you implement a form submission templating system

I need to implement a form tamplate system. The form needs to be very dynamic. It will need:
Multiple textboxes
Multiple dropdown menus
Multiple Number fields
Multiple Date fields
Single Image field
Single Submit button
Any or all of these fields can be blank but must follow the field type. Therefore letters cannot go in number fields.
The form needs to grab all the values and there could be from 1 to 300 fields in one form or more. I could not find any examples of how to implement this online. Once I grap all these values I need to store them in the database. I think I know how to store them in the database but I am puzzled on how to extract the information from the form.
Have you looked into any of the existing options, like XForms? I believe this company produces a fairly nice product: http://www.orbeon.com/
Adobe has a nice product (which even scales to enterprise levels with things like LiveCycle) if you're OK with plugins / non-html-only... although they do offer HTML rendering, but I believe it's limited.
If you are OK with the price of Sharepoint, Microsoft has InfoPath, which is sorta neat.
What are your requirements? I'm assuming ASP.NET/ASP MVC based (based on your tags). I'm also assuming cross-browser. Do you need the data back in a particular format, or as a POST to a page? What about complex validations and field bindings?

Categories