I have two Windows forms. One is Insert new member and other one is Edit member.
When inserting a new member, I can select the Membership Date. I would like to get the selected Membership Date into the Edit member form, where I have a datetimepicker.
Example: I create a new member with an ID A-15 and their membership date of 15/05/2013. When I want to edit this member, I will type the Membership ID into the Edit member form and run the program. This will load all details into textboxes and the Membership Date into the datetimepicker.
I am having trouble with the datetimepicker. How do I select the date and display it in the datetimepicker from the information in the MySQL table?
Code:
CREATE TABLE [DBO].[DONORINFO] ( [MEMBERSHIP_NO] [VARCHAR](10) PRIMARY KEY NOT NULL,
[NAME_STATE] [VARCHAR](10) NULL, [FULL_NAME] [VARCHAR](100) NULL, [STREET_NO] [VARCHAR]
(50) NULL, [STREET] [VARCHAR] (50) NULL, [CITY] [VARCHAR] (50) NULL, [TEL] [VARCHAR]
(50) NULL, [EMAIL] [VARCHAR] (50) NULL, [DIOCESE] [VARCHAR] (50) NULL, [CUS_TYPE]
[VARCHAR] (50) NULL, [MEMBERSHIP_DATE] [DATE], );
you need to get membership date value from the datatable and set it as selected date of datetimepicker
DateTime membershipdate = YourDataTable.Row[0].Field<DateTime>("MEMBERSHIP_DATE");
datetimepicker.Value= membershipdate;
Related
I'm creating a meeting program in c# using SQL. How would i go about adding multiple users from the user table to one meeting and vice versa (multiple meetings to one user from the table)
Sorry I'm new to SQL
SQL DB Format: User
[UserID] VARCHAR (50) NOT NULL,
[FirstName] VARCHAR (50) NOT NULL,
[LastName] VARCHAR (50) NOT NULL,
[Username] VARCHAR (50) NOT NULL,
[Password] VARCHAR (50) NOT NULL,
[Exc1] BIT NULL,
[Exc2] BIT NULL,
[Exc3] BIT NULL,
[Exc4] BIT NULL,
[Exc5] BIT NULL,
[Importance] INT NOT NULL,
[Meetings] VARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([UserID] ASC),
CONSTRAINT [Meetings] FOREIGN KEY ([Meetings]) REFERENCES [dbo].[Meeting] ([MeetingID])
Meeting
[MeetingID] VARCHAR (50) NOT NULL,
[Title] VARCHAR (50) NOT NULL,
[Date] DATE NOT NULL,
[StartTime] TIME (7) NOT NULL,
[EndTime] TIME (7) NOT NULL,
[Location] VARCHAR (50) NOT NULL,
[Exc1] BIT NULL,
[Exc2] BIT NULL,
[Exc3] BIT NULL,
[Exc4] BIT NULL,
[Exc5] BIT NULL,
[Summary] VARCHAR (MAX) NULL,
[UserID] VARCHAR (50) NOT NULL,
PRIMARY KEY CLUSTERED ([MeetingID] ASC),
CONSTRAINT [UserID] FOREIGN KEY ([UserID]) REFERENCES [dbo].[Users] ([UserID])
In this case it is a n to n relation and you need an additional table like
usermeetings
[UsermeetingsID]
[UserID]
[MeetingID]
And you can remove the userid columns from meeting table and meetings columns from user table
I want to implement a limited time period membership in asp.net MVC. For that, I manually introduced a new column ExpiryDate in the AspNetUsers table. When a new user registers itself this field will automatically generate an expiry date with the help of the getdate() method.
CREATE TABLE [dbo].[AspNetUsers] (
[Id] NVARCHAR (128) NOT NULL,
[Email] NVARCHAR (256) NULL,
[EmailConfirmed] BIT NOT NULL,
[PasswordHash] NVARCHAR (MAX) NULL,
[SecurityStamp] NVARCHAR (MAX) NULL,
[PhoneNumber] NVARCHAR (MAX) NULL,
[PhoneNumberConfirmed] BIT NOT NULL,
[TwoFactorEnabled] BIT NOT NULL,
[LockoutEndDateUtc] DATETIME NULL,
[LockoutEnabled] BIT NOT NULL,
[AccessFailedCount] INT NOT NULL,
[UserName] NVARCHAR (256) NOT NULL,
[RegisterDate ] DATETIME DEFAULT (getdate()) NULL,
[ExpiryDate] DATETIME DEFAULT (getdate()+(60)) NULL,
CONSTRAINT [PK_dbo.AspNetUsers] PRIMARY KEY CLUSTERED ([Id] ASC)
);
Now, I want to check that expiry date value everytime when that user tries to login. Where and what logic should I implement in my code?
I'm trying to insert in my SQL Server table the current date.
My table includes 3 files:
CREATE TABLE [dbo].[MyTable]
(
[Id] INT IDENTITY (1, 1) NOT NULL,
[Name] NVARCHAR (50) NOT NULL,
[Date] DATE
CONSTRAINT [DF_MyTable_Date] DEFAULT (getdate()) NOT NULL,
CONSTRAINT [PK_MyTable] PRIMARY KEY CLUSTERED ([Id] ASC)
)
When a new user wants to register in the system, he has only to insert his name.
In my table, the Id is generated automatically and the date too, but the date shows 01/01/0001 instead of the current day.
Where is the mistake?
if you create a datetime variable in C# like
var today_date = new DateTime();
and do a Console.WriteLine(today_date); u can see it print 0001-01-01
So this is default value of null..
Use DBNull.Value to insert a SQL NULL from C# and check the result
(Your_Date_Column) Make it Null / Not Null and give default value GetDate() but still it will not work. You have to create a trigger like this,
CREATE TRIGGER [dbo].[Trigger_Date] ON [dbo].[TableName] FOR INSERT AS BEGIN
Declare #Id int
set #Id = (select Id from inserted)
Update [dbo].[TableName]
Set Your_Date_Column = GetDate()
Where Id = #Id
END
Functions and triggers are not required. Just set a column with type Date or DateTime to NOT NULL DEFAULT CURRENT_TIMESTAMP.
Updated example code from the question:
CREATE TABLE [dbo].[MyTable]
(
[Id] INT IDENTITY (1, 1) NOT NULL,
[Name] NVARCHAR (50) NOT NULL,
[Date] DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
CONSTRAINT [PK_MyTable] PRIMARY KEY CLUSTERED ([Id] ASC)
)
I need a way to get column definition from query result. Right now I'm using SQL Server 2012.
Here is the example scenario, I have two tables which are Event and Attendant whose definitions are below :
CREATE TABLE [dbo].[Event] (
[Id] INT NOT NULL,
[Name] NVARCHAR (50) NULL,
[Description] NVARCHAR (50) NULL,
[StartDate] DATETIME NULL,
[EndDate] DATETIME NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE TABLE [dbo].[Attendant] (
[Id] INT NOT NULL,
[EventId] INT NOT NULL,
[Name] NVARCHAR (50) NULL,
[Company] NVARCHAR (50) NULL
PRIMARY KEY CLUSTERED ([Id] ASC)
);
And then I have query such as :
SELECT Event.Name as EventName, Attendant.Name as GuestName
FROM Event
INNER JOIN Attendant ON Event.Id = Attendant.EventId
How Can I get the column definition for above example query result? My objective is to generate poco class to represent each record of any query result using c#.
you can use sp_columns sproc to retrieve information about the column definition of a specified table ... like this:
exec sp_columns Attendant
Use sp_columns, it returns column information for the specified objects(tables).
Refer this link for details.
select * from information_schema.columns where table_name = '<tablename>'
this is the customers table, column 'C_BillingDay' indicates on which day the bill are due monthly for example if value is 4 thn billing due date of that customer is 4rth of each month. he has to pay his dues on 4rth ..
CREATE TABLE [dbo].[Customers](
[CID] [int] IDENTITY(1,1) NOT NULL,
[C_Name] [varchar](50) NULL,
[C_EmailID] [varchar](20) NULL,
[C_MobileNo] [varchar](20) NULL,
[C_PhoneNo] [varchar](20) NULL,
[C_HomeAddress] [varchar](max) NULL,
[C_ServiceArea] [int] NULL,
[C_AccountStatus] [int] NULL,
[C_IPAdress] [varchar](50) NULL,
[C_MACAddress] [varchar](50) NULL,
[C_Package] [int] NULL,
[C_BillingDay] [int] NULL,
[Balance] [float] NULL,
[C_AccountCreated] [datetime] NULL,
[C_AccountModified] [datetime] NULL,
payments' table:
TABLE [dbo].[Payments](
[PID] [int] IDENTITY(1,1) NOT NULL,
[CID] [int] NULL,
[Amount] [int] NULL,
[PaymentType] [int] NULL,
[Details/Comments] [varchar](max) NULL,
[DateTimeRecieved] [datetime] NULL,
[DateTimeModified] [datetime] NULL,
please help me quering all the defaulters who have not paid their dues on time by today ...
i have been trying with similar functions like DATEADD(MONTH,-1,GETDATE()) but they are not giving desired results :S
select * from Customers,payments
where Payments.DateTimeRecieved
NOT BETWEEN GETDATE() AND DATEADD(MONTH,-1,GETDATE())
From the limited system information given, I suspect there would be two relevant processes.
The first a daily job which does an UPDATE on the [Balance] column for all records in [Customers] based on [C_Package] (perhaps this indicates a monthly fee stored elsewhere), [C_AccountStatus] (perhaps indicating whether they are active), [C_BillingDay], and todays date.
Once that is done all you need to do is
SELECT [CID] FROM [dbo].[Customers] WHERE [Balance] > 0
Hope this helps.
Edit ...
To select Customers who haven't made a payment (though the logic seems flawed):
SELECT c.[CID]
FROM [Customers] c
WHERE c.[CID] NOT IN
(SELECT p.[CID] FROM [Payments] p
WHERE p.[DateTimeRecieved] BETWEEN GETDATE() AND DATEADD(MONTH,-1,GETDATE()))
(There's probably a way more elegant query than that!)
What about checking if the balance is not 0 and that today is the date of their payment. Something like:
select * from customers, payments where customers.balance > 0 and todays_date >= billdate;
its a bit abstract because i dont really know what language we are dealing with or what form your dates are in.
I am also making an assumption that they pay off their entire balance when they pay their dues