Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

trouble with bindingsource Datasource in C# with SQL Server Database

I created Below Table in our Database and I used C# and Binding Source to connect in my database. I have some datetime fields that I need do some addition and subtraction operations on that fields.
I bounded datetime Text fields in C# form to two textboxes and I added two Leave and textchange eventhandler for them and then I got dates and I did my calculation operations. Now my question is there any way to get directly datetime value from Binding source without other objects (for example without using textbox text values).

USE [TradeSaleMainDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DepoCosts](
    [TrDepoCostsID] [bigint] NOT NULL,
    [TrDepoFiscYear] [smallint] NOT NULL,
    [TrDepoSaleCustomerCode] [int] NOT NULL,
    [TrDepoSaleTreatyCode] [int] NOT NULL,
    [TrDepoRegisterDate] [datetime] NOT NULL,
    [TrDepoDateFrom] [datetime] NOT NULL,
    [TrDepoDateTo] [datetime] NOT NULL,
    [TrDepoCostPersentage] [decimal](18, 2) NOT NULL,
    [TrDepoRemainQ] [decimal](18, 2) NOT NULL,
    [TrDepoRegisteredBy] [smallint] NOT NULL,
    [TrDepoDepoCostQ] [decimal](18, 2) NOT NULL,
    [TrDepoDepoCostR] [decimal](18, 2) NOT NULL,
    [TrDepoTotalOrder] [decimal](18, 2) NOT NULL,
    [TrDepoRemainOrder] [decimal](18, 2) NOT NULL,
    [TrDepoIsCancel] [bit] NOT NULL,
    [TrDepoCanceledBy] [smallint] NULL,
    [TrDepoCancelDate] [datetime] NULL,
CONSTRAINT [PK_DepoCosts] PRIMARY KEY CLUSTERED 
(
    [TrDepoCostsID] ASC,
    [TrDepoFiscYear] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DepoCosts] ADD  CONSTRAINT [DF_DepoCosts_DpIsCancel]  DEFAULT ((0)) FOR [DpIsCancel]
GO

My C# code is as Follow:

private void TxtDateFrom_Leave(object sender, EventArgs e)
{
    TxtDateTo.Text = ConvertToCustomerOmitDate(DateTime.Parse(T2.Text));
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

try as follow:

private void YourBindingSourceName_PositionChanged(object sender, EventArgs e)
{
   TxtDateTo.Text = ConvertToCustomerOmitDate(DateTime.Parse(T2.Text));
}

and you should bind that event to your binding source.
Following This Picture

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading