Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I currently have a mysql data table that fills up when people complete a form. I then have my visual studio c# bot pull this data and do what I want. The table numbers the table using integers that increase by 1 each time. My bot looks in the table for id 1 and adds it.
The problem I have is that once my bot completes what someone wants and deletes the data, it does not recognize to go onto the next one since that id is not 1 and something else, like 2. I tried to have my c# bot add 1 to a variable each time and then have that variable represent the id so that every time the bot completed something it would go onto the next id. The problem with this was that every time the bot completed with one person the variable was reset back to 1. I am stuck now and can't figure out what to do. Any help would be great.
This is currently the string I use "select name from names where id = 1". If I can somehow instead of having the id = 1 and have it look for the next lowest id in my table then that would work.
Edit: Actually I think I figured out how to have the last added id be used. I will post it if I find it.
In MySQL, if you want the lowest ID then you could do something like this:
SELECT
Name
FROM
Names
ORDER BY ID
Limit 1
Is that what you are looking for?
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have this issue in my c# MVC App where i have a receipt and this receipt has a receipt number and i select the last receipt number inserted in the database and add 1 to it, the problem appears when 2 users submitting the receipt at the same time. What happens is that they both get the same receipt number and they both insert into the database, unfortunately one is inserted and the other gives exception and rollback the whole operation. So my question is there a way to prevent this from happening, in other words reserve a receipt number taken by user, so it won’t be used by the other user.
Thanks in advance.
If using sql server you should probably use an IDENTITY column. Another option would be to use a GUID as the key.
So you need to reset the receipt number for each new year? You could make a separate call to get the receipt number first without doing inserts into other tables. This would reserve a number and return immediately. You could use an identity column for this, either a separate table per year or reset the identity value and truncate at the start of each new year. Or you could have a table for Ids with Year and ReceiptNumber as the PK and insert a new row with incrementing receipt number by one.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Working on an MVC application. I have hundreds of users. Currently I'm trying to give some of our top users (maybe 10) a discount if they log-in through their assigned work-place e-mails. The price break is shown in the Search result, Product page, Shopping Cart, and Checkout page. I had to work on this quickly to hack it for the holiday season, so currently the way I am doing this is something like this:
ProductDetails.aspx
if (user == "at#at.com") {
Product. Price * 20
}
else {
Product.Price
}
As you can see, this works for now, however I'd have to do this for all 4 pages, and as our discounted users increase, this may become too long and mundane. I'm looking at a way to go around having such a long if/else statement, and was wondering if it makes sense to use a stored procedure instead or a method?
I would suggest to add a discount field to the user table or any appropriate table in the database and save the discount info there. You can also create a new table that holds the discount information tied up to the different users and manage to return the discount value instead of going through an if/else statement.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a website dropdown that is populated from a SQL query. The values in the dropdown are from a table column and are like:
ABC-0123
ABC-0124
ABC-0125
ABC-0126.01
ABC-0126.02
ABC-0127
DEF-0123
DEF-0124
DEF-0125.1.01
DEF-0125.1.02
DEF-0125.2
I have a button to generate a new number based on what is selected in the dropdown. For example, if ABC-0125 is selected, ABC-0128 would need to be created since it's the next number in sequence. If ABC-0126.01 is selected, ABC-0126.03 would need to be created.
I'm looking for ideas on how to perform this. I considered just using the dropdown or querying the database directly.
I've split the selected value as a start:
String strDocFamily = drpDocFamily.SelectedValue;
string[] strDocTiers = strDocFamily.Split('.');
This may be open ended, but I'm looking for some suggestions on how to proceed. Thank you.
A solution might be to split the storage of the data into two or more columns, one for the alphabetic part ('ABC') another for the 'family' (0128 - the first set of digits) and others for the other tiers. You could then directly look up the maximum value of the 'family' column based on alphabetic. For example:
SELECT MAX(family-number)
FROM table-name
WHERE alpha-part='ABC';
Here is a UniqueID generator that can be easily adapted to generate a similar sequence to the one you need.
https://stackoverflow.com/a/39312025/2495728
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am trying a develop a Math Practice web application using ASP.NET (not MVC), which allows Users to perform Multiple choice or simply type an answer, click a button and see answer.
The first idea that comes to mind is simply get permission to use a book, grab all the questions and answers using a DB and display the right answer. But how would I display the answer or the show me how the answer was derived.
My confusion is; how does this work?:
Do I have to write all the formulas and answer myself?
Are there programs for this?
I do not even know where to start.
What I would like to do is have the user select an answer, if the answer is wrong, they can click the show me button.
I am looking to either write this in C#, Visual Basic using JQuery on the front end.
Just need some direction.
Thanks my friends.
When I was in college I had to do something very similar.
What I did is stored expressions 4 + 5; 1 * 6 in database and then pushed those expressions to evaluate on run-time because it is pretty easy in C#.
It takes expression from database 2 + 2
It evaluates the expression on run-time producing result 4
You get your result and show it to user or do whatever with it
More info on how exactly to do that: http://www.c-sharpcorner.com/UploadFile/mgold/CodeDomCalculator08082005003253AM/CodeDomCalculator.aspx
I don't think you need to evaluate a stored expression. Since you just want the user to enter multiple choice or the answer itself, just set up your database as follows:
QuestionAnswers:
ID (uniqueidentifier) (primary)
QuestionText (varchar)
QuestionAnswer (varchar)
ShowMeHowEquation (varchar)
Then, display the ShowMeHowEquation via jQuery like so:
Show Me How
<div class="showMeHowEquation">Database driven contents here...</div>
<script>
$(document).ready(function() {
$('.showMeHow')click(function() {
$(this).next('.showMeHowEquation').slideDown();
});
});
</script>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'd like to display a repeating event on a date/time display in an app. This date time display can take the form of a calendar, but it could also just be a list of upcoming events.
What is the best way to handle tracking this event that can repeat?
For example: Should the event be stored once in the database and projected out / repeated several times in the display code? Should the event be stored several times and then just rendered?
I did something like this before and I based my schema off of SQL Servers sysschedules table.
http://technet.microsoft.com/en-us/library/ms178644.aspx
The schema linked above will allow you to store the schedule for a job (event). Then you can calculate what dates the event occurs on based off of the schedule. This may be a lengthy calculation, so I would try to cache that result somewhere.
I think it depends on type of event it is. Is it like Christmas where once it comes along and happens you really aren't interested in it until the next occurrence? Or is it a task like, "Make sure I call my mom every month", where if it happens and you missed it you wouldn't want it to go away?
One way I recently implemented the latter was to have a record that had next_occurrence (date), reoccurence_period (weekly, monthly, yearly, etc) columns. So that as the next occurence approched it would show up in the list. Once it passed the list item would have a recycle icon that once pressed would update the record to the next future occurence.
Again, i'm not sure if this applies to your situation, but it worked well for mine.