Home > Software engineering >  trouble with bindingsource Datasource in C# with SQL Server Database
trouble with bindingsource Datasource in C# with SQL Server Database

Time:12-22

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));
}

CodePudding user response:

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

  •  Tags:  
  • c#
  • Related