How can I change the stock in a Microsoft Access database? [closed] - c#

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I'm having a problem altering the stock in my database. What I am looking to do is to minus the stock in my database by 1 when the button 'Reserve Item' is clicked on. So say the stock is sitting at 10. When I reserve an item I want the stock in the database to automatically decrease to 9.
Any ideas on how this can be achieved Using ASP.NET with C#?

Even shorter:
update stock_table
set stock_quantity = stock_quantity - 1
where stock_id = xxx

The SQL UPDATE statement
What you really want to do is something like this:
UPDATE stock_table
SET stock_quantity = (SELECT stock_quantity - 1 FROM stock_table WHERE stock_id = '#####')
WHERE stock_id = '#####'
'######' presents the id of your item (not sure if you are using int or varchar/text or guid).

Related

C# code for Insert data to a table with ReferenceKey using Entity Mode [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
can anyone tell me how to insert data to
Table Student has columns {stuId Name Age}
Table School has columns {classId Year sName}
"sName" is a reference key from Student Table
I want to insert data using Entity Model C#
Try this to add student:
Student student = new Student(){studId="", Name="", Age=""};
myEntities.Students.AddObject(student);
myEntities.SaveChanges();
Adding school:
School school = new School(){classId="", Year = year, sName=""};
myEntities.Schools.AddObject(school);
myEntities.SaveChanges();
I hope this helps.
String SchooID = getNewID();
Schools schl = new Schools();
schl.school_reference = SchooID;
schl.school_name = "Ananda Collage";
schl.StudentReference.Value = cecbContext.Students.First(i => i.stud_name == "Josh");
cecbContext.AddToSchools(schl);
cecbContext.SaveChanges();
I found the answer in this way. this worked to me successfully. Thanks a lot for your help guys

How to add a wiki page through ItemAdded event receiver coding on the addition of a new item in a list? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have a list named 'List1' in which I have 'title ' and 'WikiLink' columns. I want to add a wiki page on the addition of a new item using ItemAdded event receiver code and update the link on 'WikiLink' column. Please help me out in this. I have been stuck on this for quite a while.
Thanks.
To create wiki page, you will have to add new item into one of the libraries that accepts wiki pages. Typically it's Site Pages, with code more less like this:
var l = (SPDocumentLibrary) SPContext.Current.Web.Lists["Site Pages"];
var folder = l.RootFolder;
var f = folder.Files.Add(string.Format("{0}/{1}", folder.ServerRelativeUrl.TrimEnd("/"), "MyWiki.aspx"), SPTemplateFileType.StandardPage);
//Site Absolute url + Site-relative Url, more info on MSDN.
var url = string.Format("{0}/{1}", SPContext.Current.Site.Url.TrimEnd("/"), f.Url);

variable name with a white space [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to have a variable name with a white space.
Am passing this collection to a gridview and i need the title to have a white space instead of an underscore
var registrationReport = (from r in BankMedEntity.Customers
select new {r.Id,Customer Type = r.CustomerType_Id });
Any idea on how i can accomplish that?
I need to have the title as "Customer Type" instead of "CustomerType_Id"
You cannot, c# does not allow spaces in variable names. They would be considered different words and the compiler will go "Ahh...What do you mean?"
Turn this to false
AutoGenerateColumns="True"
And add your own Bound columns to the Gridview. You will be able to give the columns whatever names you want
Unfortunately that is impossible; the compiler has no way of figuring out that the two separate words are actually part of the same variable name.
No space is allowed in variable name.
If you want the title of the gridview with no underscore, you should edit the girdview definition in .aspx file.

Linq to find the length of the value of the column in the list [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a list and a column; the column might have many values, and each value's length may vary.
If the length exceeds 100, I want to append /n at the end of it.
Need your help.
I give it a try, though a lot of questions are open (what type of list, what a column, ...).
In short: you can use String.Insert to insert text at a specified postition.
Assuming you have a List<Foo>, the class Foo has a string property Value (your column). If it's Length exceeds 100 the line should be wrapped:
foreach(Foo foo in foos)
{
if(foo.Value.Length > 100)
foo.Value = foo.Value.Insert(100, Environment.NewLine);
}
http://msdn.microsoft.com/en-us/library/system.string.insert.aspx
Here's running code with sample data.
http://ideone.com/sUKLk

DOB in database, after one year I want to increment age and update into database also [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am storing Date of Birth in database, after one year I want to increment age and update into database also.
Store the date of birth. Make age a computed column:
CREATE TABLE [Table](
/* Columns */
[DateOfBirth] [date] NULL,
[Age] AS CASE
WHEN DATEADD(year,-DATEDIFF(year,DateOfBirth,CURRENT_TIMESTAMP),CURRENT_TIMESTAMP) < DateOfBirth THEN
DATEDIFF(year,DateOfBirth,CURRENT_TIMESTAMP) - 1
ELSE
DATEDIFF(year,DateOfBirth,CURRENT_TIMESTAMP)
END,
/* Constraints, etc */
)
This way you don't have to do any work yourself.
you can implement the age as an calculated value. This way the age is always correct at the moment of querying (http://www.mssqltips.com/sqlservertip/1682/using-computed-columns-in-sql-server-with-persisted-values/)

Categories