473,803 Members | 3,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Databinding formatted dates on a tab control

I'm binding date fields from entity objects and formatting the output in the
text box in short date format.

Code:

BindDateField(M e.txtCheckIn, "Text", reservation.Boo kingDetail, "CheckIn")
BindDateField(M e.txtCustTravle Date, "Text", reservation.Boo kingDetail,
"CheckIn")
BindDateField(M e.txtCheckOut, "Text", reservation.Boo kingDetail, "CheckOut")

Code:

Public Sub BindDateField(B yVal control As Control, ByVal propertyName As
String, ByVal dataSource As Object, ByVal dataMember As String)

For index = control.DataBin dings.Count - 1 To 0 Step -1
dbd = control.DataBin dings.Item(inde x)
If dbd.PropertyNam e = propertyName Then
control.DataBin dings.Remove(db d)
End If
Next
dbd = New Binding(propert yName, dataSource, dataMember)
control.DataBin dings.Add(dbd)

End Sub

Private Sub oBinding_Format (ByVal sender As Object, ByVal e As
System.Windows. Forms.ConvertEv entArgs) Handles dbd.Format

e.Value = Format(e.Value, "D")

End Sub

When I run the app. the dates in the textboxes are formatted correctly,
however the textboxes are on a tab control and when I click onto a different
tab and then back all the dates show in the format 01/01/2005 00:00:00.

Any ideas?

Nov 21 '05 #1
3 1728
Hi

Based on my test, it seems that I can not reproduce the problem.
I binding the textbox to Table, the binding code is as follows.

Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TabControl1 As System.Windows. Forms.TabContro l
Friend WithEvents TabPage1 As System.Windows. Forms.TabPage
Friend WithEvents TabPage2 As System.Windows. Forms.TabPage
Friend WithEvents TextBox1 As System.Windows. Forms.TextBox
Friend WithEvents TextBox2 As System.Windows. Forms.TextBox
Friend WithEvents SqlDataAdapter1 As
System.Data.Sql Client.SqlDataA dapter
Friend WithEvents SqlSelectComman d1 As System.Data.Sql Client.SqlComma nd
Friend WithEvents SqlInsertComman d1 As System.Data.Sql Client.SqlComma nd
Friend WithEvents SqlUpdateComman d1 As System.Data.Sql Client.SqlComma nd
Friend WithEvents SqlDeleteComman d1 As System.Data.Sql Client.SqlComma nd
Friend WithEvents SqlConnection1 As System.Data.Sql Client.SqlConne ction
Friend WithEvents DataSet11 As TestBinding.Dat aSet1
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.TabControl1 = New System.Windows. Forms.TabContro l
Me.TabPage1 = New System.Windows. Forms.TabPage
Me.TabPage2 = New System.Windows. Forms.TabPage
Me.TextBox1 = New System.Windows. Forms.TextBox
Me.TextBox2 = New System.Windows. Forms.TextBox
Me.SqlDataAdapt er1 = New System.Data.Sql Client.SqlDataA dapter
Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.SqlInsertCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.SqlUpdateCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.SqlDeleteCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.SqlConnectio n1 = New System.Data.Sql Client.SqlConne ction
Me.DataSet11 = New TestBinding.Dat aSet1
Me.TabControl1. SuspendLayout()
Me.TabPage1.Sus pendLayout()
Me.TabPage2.Sus pendLayout()
CType(Me.DataSe t11,
System.Componen tModel.ISupport Initialize).Beg inInit()
Me.SuspendLayou t()
'
'TabControl1
'
Me.TabControl1. Controls.Add(Me .TabPage1)
Me.TabControl1. Controls.Add(Me .TabPage2)
Me.TabControl1. Dock = System.Windows. Forms.DockStyle .Fill
Me.TabControl1. Location = New System.Drawing. Point(0, 0)
Me.TabControl1. Name = "TabControl 1"
Me.TabControl1. SelectedIndex = 0
Me.TabControl1. Size = New System.Drawing. Size(292, 266)
Me.TabControl1. TabIndex = 0
'
'TabPage1
'
Me.TabPage1.Con trols.Add(Me.Te xtBox1)
Me.TabPage1.Loc ation = New System.Drawing. Point(4, 22)
Me.TabPage1.Nam e = "TabPage1"
Me.TabPage1.Siz e = New System.Drawing. Size(284, 240)
Me.TabPage1.Tab Index = 0
Me.TabPage1.Tex t = "TabPage1"
'
'TabPage2
'
Me.TabPage2.Con trols.Add(Me.Te xtBox2)
Me.TabPage2.Loc ation = New System.Drawing. Point(4, 22)
Me.TabPage2.Nam e = "TabPage2"
Me.TabPage2.Siz e = New System.Drawing. Size(284, 240)
Me.TabPage2.Tab Index = 1
Me.TabPage2.Tex t = "TabPage2"
'
'TextBox1
'
Me.TextBox1.Dat aBindings.Add(N ew
System.Windows. Forms.Binding(" Text", Me.DataSet11, "Orders.Shipped Date"))
Me.TextBox1.Loc ation = New System.Drawing. Point(88, 80)
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Tab Index = 0
Me.TextBox1.Tex t = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Dat aBindings.Add(N ew
System.Windows. Forms.Binding(" Text", Me.DataSet11, "Orders.Shipped Date"))
Me.TextBox2.Loc ation = New System.Drawing. Point(88, 96)
Me.TextBox2.Nam e = "TextBox2"
Me.TextBox2.Tab Index = 0
Me.TextBox2.Tex t = "TextBox2"
'
'SqlDataAdapter 1
'
Me.SqlDataAdapt er1.DeleteComma nd = Me.SqlDeleteCom mand1
Me.SqlDataAdapt er1.InsertComma nd = Me.SqlInsertCom mand1
Me.SqlDataAdapt er1.SelectComma nd = Me.SqlSelectCom mand1
Me.SqlDataAdapt er1.TableMappin gs.AddRange(New
System.Data.Com mon.DataTableMa pping() {New
System.Data.Com mon.DataTableMa pping("Table", "Orders", New
System.Data.Com mon.DataColumnM apping() {New
System.Data.Com mon.DataColumnM apping("OrderID ", "OrderID"), New
System.Data.Com mon.DataColumnM apping("Custome rID", "CustomerID "), New
System.Data.Com mon.DataColumnM apping("Employe eID", "EmployeeID "), New
System.Data.Com mon.DataColumnM apping("OrderDa te", "OrderDate" ), New
System.Data.Com mon.DataColumnM apping("Require dDate", "RequiredDate") , New
System.Data.Com mon.DataColumnM apping("Shipped Date", "ShippedDat e"), New
System.Data.Com mon.DataColumnM apping("ShipVia ", "ShipVia"), New
System.Data.Com mon.DataColumnM apping("Freight ", "Freight"), New
System.Data.Com mon.DataColumnM apping("ShipNam e", "ShipName") , New
System.Data.Com mon.DataColumnM apping("ShipAdd ress", "ShipAddres s"), New
System.Data.Com mon.DataColumnM apping("ShipCit y", "ShipCity") , New
System.Data.Com mon.DataColumnM apping("ShipReg ion", "ShipRegion "), New
System.Data.Com mon.DataColumnM apping("ShipPos talCode", "ShipPostalCode "),
New System.Data.Com mon.DataColumnM apping("ShipCou ntry", "ShipCountry")} )})
Me.SqlDataAdapt er1.UpdateComma nd = Me.SqlUpdateCom mand1
'
'SqlSelectComma nd1
'
Me.SqlSelectCom mand1.CommandTe xt = "SELECT OrderID, CustomerID,
EmployeeID, OrderDate, RequiredDate, ShippedDate, Shi" & _
"pVia, Freight, ShipName, ShipAddress, ShipCity, ShipRegion,
ShipPostalCode, Ship" & _
"Country FROM Orders"
Me.SqlSelectCom mand1.Connectio n = Me.SqlConnectio n1
'
'SqlInsertComma nd1
'
Me.SqlInsertCom mand1.CommandTe xt = "INSERT INTO Orders(Customer ID,
EmployeeID, OrderDate, RequiredDate, ShippedDate, " & _
"ShipVia, Freight, ShipName, ShipAddress, ShipCity, ShipRegion,
ShipPostalCode, S" & _
"hipCountry ) VALUES (@CustomerID, @EmployeeID, @OrderDate,
@RequiredDate, @Shippe" & _
"dDate, @ShipVia, @Freight, @ShipName, @ShipAddress, @ShipCity,
@ShipRegion, @Shi" & _
"pPostalCod e, @ShipCountry); SELECT OrderID, CustomerID,
EmployeeID, OrderDate, R" & _
"equiredDat e, ShippedDate, ShipVia, Freight, ShipName, ShipAddress,
ShipCity, Shi" & _
"pRegion, ShipPostalCode, ShipCountry FROM Orders WHERE (OrderID =
@@IDENTITY)"
Me.SqlInsertCom mand1.Connectio n = Me.SqlConnectio n1
Me.SqlInsertCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Customer ID",
System.Data.Sql DbType.NVarChar , 5, "CustomerID "))
Me.SqlInsertCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Employee ID",
System.Data.Sql DbType.Int, 4, "EmployeeID "))
Me.SqlInsertCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@OrderDat e",
System.Data.Sql DbType.DateTime , 8, "OrderDate" ))
Me.SqlInsertCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Required Date",
System.Data.Sql DbType.DateTime , 8, "RequiredDate") )
Me.SqlInsertCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShippedD ate",
System.Data.Sql DbType.DateTime , 8, "ShippedDat e"))
Me.SqlInsertCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShipVia" , System.Data.Sql DbType.Int,
4, "ShipVia"))
Me.SqlInsertCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Freight" , System.Data.Sql DbType.Money,
8, "Freight"))
Me.SqlInsertCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShipName ",
System.Data.Sql DbType.NVarChar , 40, "ShipName") )
Me.SqlInsertCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShipAddr ess",
System.Data.Sql DbType.NVarChar , 60, "ShipAddres s"))
Me.SqlInsertCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShipCity ",
System.Data.Sql DbType.NVarChar , 15, "ShipCity") )
Me.SqlInsertCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShipRegi on",
System.Data.Sql DbType.NVarChar , 15, "ShipRegion "))
Me.SqlInsertCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShipPost alCode",
System.Data.Sql DbType.NVarChar , 10, "ShipPostalCode "))
Me.SqlInsertCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShipCoun try",
System.Data.Sql DbType.NVarChar , 15, "ShipCountr y"))
'
'SqlUpdateComma nd1
'
Me.SqlUpdateCom mand1.CommandTe xt = "UPDATE Orders SET CustomerID =
@CustomerID, EmployeeID = @EmployeeID, OrderDate =" & _
" @OrderDate, RequiredDate = @RequiredDate, ShippedDate =
@ShippedDate, ShipVia =" & _
" @ShipVia, Freight = @Freight, ShipName = @ShipName, ShipAddress =
@ShipAddress," & _
" ShipCity = @ShipCity, ShipRegion = @ShipRegion, ShipPostalCode =
@ShipPostalCod" & _
"e, ShipCountry = @ShipCountry WHERE (OrderID = @Original_Order ID)
AND (CustomerI" & _
"D = @Original_Custo merID OR @Original_Custo merID IS NULL AND
CustomerID IS NULL)" & _
" AND (EmployeeID = @Original_Emplo yeeID OR @Original_Emplo yeeID IS
NULL AND Empl" & _
"oyeeID IS NULL) AND (Freight = @Original_Freig ht OR
@Original_Freig ht IS NULL AN" & _
"D Freight IS NULL) AND (OrderDate = @Original_Order Date OR
@Original_Order Date I" & _
"S NULL AND OrderDate IS NULL) AND (RequiredDate =
@Original_Requi redDate OR @Ori" & _
"ginal_Required Date IS NULL AND RequiredDate IS NULL) AND
(ShipAddress = @Origina" & _
"l_ShipAddr ess OR @Original_ShipA ddress IS NULL AND ShipAddress IS
NULL) AND (Shi" & _
"pCity = @Original_ShipC ity OR @Original_ShipC ity IS NULL AND
ShipCity IS NULL) A" & _
"ND (ShipCountry = @Original_ShipC ountry OR @Original_ShipC ountry
IS NULL AND Shi" & _
"pCountry IS NULL) AND (ShipName = @Original_ShipN ame OR
@Original_ShipN ame IS NU" & _
"LL AND ShipName IS NULL) AND (ShipPostalCode =
@Original_ShipP ostalCode OR @Orig" & _
"inal_ShipPosta lCode IS NULL AND ShipPostalCode IS NULL) AND
(ShipRegion = @Origi" & _
"nal_ShipRe gion OR @Original_ShipR egion IS NULL AND ShipRegion IS
NULL) AND (Ship" & _
"Via = @Original_ShipV ia OR @Original_ShipV ia IS NULL AND ShipVia
IS NULL) AND (S" & _
"hippedDate = @Original_Shipp edDate OR @Original_Shipp edDate IS
NULL AND ShippedD" & _
"ate IS NULL); SELECT OrderID, CustomerID, EmployeeID, OrderDate,
RequiredDate, S" & _
"hippedDate , ShipVia, Freight, ShipName, ShipAddress, ShipCity,
ShipRegion, ShipP" & _
"ostalCode, ShipCountry FROM Orders WHERE (OrderID = @OrderID)"
Me.SqlUpdateCom mand1.Connectio n = Me.SqlConnectio n1
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Customer ID",
System.Data.Sql DbType.NVarChar , 5, "CustomerID "))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Employee ID",
System.Data.Sql DbType.Int, 4, "EmployeeID "))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@OrderDat e",
System.Data.Sql DbType.DateTime , 8, "OrderDate" ))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Required Date",
System.Data.Sql DbType.DateTime , 8, "RequiredDate") )
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShippedD ate",
System.Data.Sql DbType.DateTime , 8, "ShippedDat e"))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShipVia" , System.Data.Sql DbType.Int,
4, "ShipVia"))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Freight" , System.Data.Sql DbType.Money,
8, "Freight"))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShipName ",
System.Data.Sql DbType.NVarChar , 40, "ShipName") )
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShipAddr ess",
System.Data.Sql DbType.NVarChar , 60, "ShipAddres s"))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShipCity ",
System.Data.Sql DbType.NVarChar , 15, "ShipCity") )
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShipRegi on",
System.Data.Sql DbType.NVarChar , 15, "ShipRegion "))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShipPost alCode",
System.Data.Sql DbType.NVarChar , 10, "ShipPostalCode "))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@ShipCoun try",
System.Data.Sql DbType.NVarChar , 15, "ShipCountr y"))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _OrderID",
System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "OrderID",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _CustomerID",
System.Data.Sql DbType.NVarChar , 5, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "CustomerID ",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _EmployeeID",
System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "EmployeeID ",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _Freight",
System.Data.Sql DbType.Money, 8, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "Freight",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _OrderDate",
System.Data.Sql DbType.DateTime , 8, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "OrderDate" ,
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _RequiredDate",
System.Data.Sql DbType.DateTime , 8, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "RequiredDa te",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShipAddress",
System.Data.Sql DbType.NVarChar , 60, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "ShipAddres s",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShipCity",
System.Data.Sql DbType.NVarChar , 15, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "ShipCity",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShipCountry",
System.Data.Sql DbType.NVarChar , 15, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "ShipCountr y",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShipName",
System.Data.Sql DbType.NVarChar , 40, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "ShipName",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShipPostalCode ",
System.Data.Sql DbType.NVarChar , 10, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "ShipPostalCode ",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShipRegion",
System.Data.Sql DbType.NVarChar , 15, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "ShipRegion ",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShipVia",
System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "ShipVia",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShippedDate",
System.Data.Sql DbType.DateTime , 8, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "ShippedDat e",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlUpdateCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@OrderID" , System.Data.Sql DbType.Int,
4, "OrderID"))
'
'SqlDeleteComma nd1
'
Me.SqlDeleteCom mand1.CommandTe xt = "DELETE FROM Orders WHERE
(OrderID = @Original_Order ID) AND (CustomerID = @Origina" & _
"l_Customer ID OR @Original_Custo merID IS NULL AND CustomerID IS
NULL) AND (Employ" & _
"eeID = @Original_Emplo yeeID OR @Original_Emplo yeeID IS NULL AND
EmployeeID IS NU" & _
"LL) AND (Freight = @Original_Freig ht OR @Original_Freig ht IS NULL
AND Freight IS" & _
" NULL) AND (OrderDate = @Original_Order Date OR @Original_Order Date
IS NULL AND O" & _
"rderDate IS NULL) AND (RequiredDate = @Original_Requi redDate OR
@Original_Requi r" & _
"edDate IS NULL AND RequiredDate IS NULL) AND (ShipAddress =
@Original_ShipA ddres" & _
"s OR @Original_ShipA ddress IS NULL AND ShipAddress IS NULL) AND
(ShipCity = @Ori" & _
"ginal_Ship City OR @Original_ShipC ity IS NULL AND ShipCity IS NULL)
AND (ShipCoun" & _
"try = @Original_ShipC ountry OR @Original_ShipC ountry IS NULL AND
ShipCountry IS " & _
"NULL) AND (ShipName = @Original_ShipN ame OR @Original_ShipN ame IS
NULL AND ShipN" & _
"ame IS NULL) AND (ShipPostalCode = @Original_ShipP ostalCode OR
@Original_ShipP os" & _
"talCode IS NULL AND ShipPostalCode IS NULL) AND (ShipRegion =
@Original_ShipR egi" & _
"on OR @Original_ShipR egion IS NULL AND ShipRegion IS NULL) AND
(ShipVia = @Origi" & _
"nal_ShipVi a OR @Original_ShipV ia IS NULL AND ShipVia IS NULL) AND
(ShippedDate =" & _
" @Original_Shipp edDate OR @Original_Shipp edDate IS NULL AND
ShippedDate IS NULL)" & _
""
Me.SqlDeleteCom mand1.Connectio n = Me.SqlConnectio n1
Me.SqlDeleteCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _OrderID",
System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "OrderID",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlDeleteCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _CustomerID",
System.Data.Sql DbType.NVarChar , 5, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "CustomerID ",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlDeleteCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _EmployeeID",
System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "EmployeeID ",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlDeleteCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _Freight",
System.Data.Sql DbType.Money, 8, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "Freight",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlDeleteCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _OrderDate",
System.Data.Sql DbType.DateTime , 8, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "OrderDate" ,
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlDeleteCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _RequiredDate",
System.Data.Sql DbType.DateTime , 8, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "RequiredDa te",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlDeleteCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShipAddress",
System.Data.Sql DbType.NVarChar , 60, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "ShipAddres s",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlDeleteCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShipCity",
System.Data.Sql DbType.NVarChar , 15, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "ShipCity",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlDeleteCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShipCountry",
System.Data.Sql DbType.NVarChar , 15, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "ShipCountr y",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlDeleteCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShipName",
System.Data.Sql DbType.NVarChar , 40, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "ShipName",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlDeleteCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShipPostalCode ",
System.Data.Sql DbType.NVarChar , 10, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "ShipPostalCode ",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlDeleteCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShipRegion",
System.Data.Sql DbType.NVarChar , 15, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "ShipRegion ",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlDeleteCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShipVia",
System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "ShipVia",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
Me.SqlDeleteCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Original _ShippedDate",
System.Data.Sql DbType.DateTime , 8, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "ShippedDat e",
System.Data.Dat aRowVersion.Ori ginal, Nothing))
'
'SqlConnection1
'
Me.SqlConnectio n1.ConnectionSt ring = "workstatio n
id=""SHA-VPHUANG-03"";packet size=4096;integ rated security=SSPI;d ata so" & _
"urce=""sha-test-hf"";persist security info=False;init ial
catalog=Northwi nd"
'
'DataSet11
'
Me.DataSet11.Da taSetName = "DataSet1"
Me.DataSet11.Lo cale = New System.Globaliz ation.CultureIn fo("zh-CN")
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 266)
Me.Controls.Add (Me.TabControl1 )
Me.Name = "Form1"
Me.Text = "Form1"
Me.TabControl1. ResumeLayout(Fa lse)
Me.TabPage1.Res umeLayout(False )
Me.TabPage2.Res umeLayout(False )
CType(Me.DataSe t11,
System.Componen tModel.ISupport Initialize).End Init()
Me.ResumeLayout (False)

End Sub

#End Region

Dim WithEvents db As Binding
Dim WithEvents db1 As Binding
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
db = Me.TextBox1.Dat aBindings(0)
db1 = Me.TextBox2.Dat aBindings(0)
Me.SqlDataAdapt er1.Fill(Me.Dat aSet11)
End Sub

Private Sub db_Format(ByVal sender As Object, ByVal e As
System.Windows. Forms.ConvertEv entArgs) Handles db.Format
e.Value = Format(e.Value, "D")
End Sub

Private Sub db1_Format(ByVa l sender As Object, ByVal e As
System.Windows. Forms.ConvertEv entArgs) Handles db1.Format
e.Value = Format(e.Value, "d")
End Sub
End Class
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #2
Hi,

"funkyMonke y" <fu*********@ne wsgroups.nospam > wrote in message
news:9F******** *************** ***********@mic rosoft.com...
I'm binding date fields from entity objects and formatting the output in
the
text box in short date format.

Code:

BindDateField(M e.txtCheckIn, "Text", reservation.Boo kingDetail, "CheckIn")
BindDateField(M e.txtCustTravle Date, "Text", reservation.Boo kingDetail,
"CheckIn")
BindDateField(M e.txtCheckOut, "Text", reservation.Boo kingDetail,
"CheckOut")

Code:

Public Sub BindDateField(B yVal control As Control, ByVal propertyName As
String, ByVal dataSource As Object, ByVal dataMember As String)

For index = control.DataBin dings.Count - 1 To 0 Step -1
dbd = control.DataBin dings.Item(inde x)
If dbd.PropertyNam e = propertyName Then
control.DataBin dings.Remove(db d)
End If
Next
dbd = New Binding(propert yName, dataSource, dataMember)
control.DataBin dings.Add(dbd)

End Sub

Private Sub oBinding_Format (ByVal sender As Object, ByVal e As
System.Windows. Forms.ConvertEv entArgs) Handles dbd.Format

e.Value = Format(e.Value, "D")

End Sub
If you use a WithEvents dbd field then you would need one foreach Binding.
Like it is now, at the best all initial formatting works but after that then
only the last binding can work.

Instead of using a WithEvents field you should use AddHandler to add
eventhandlers and RemoveHandler to remove them:

Public Sub BindDateField( ByVal control As Control, ByVal propertyName As
String, ByVal dataSource As Object, ByVal dataMember As String)
Dim bnd As Binding

' remove possible binding
bnd = control.DataBin dings("Text")
If (Not bnd Is Nothing) Then
RemoveHandler bnd.Format, AddressOf FormatDt
control.DataBin dings.Remove(bn d)
End If

' add binding
bnd = New Binding("Text", dataSource, dataMember)
AddHandler bnd.Format, AddressOf FormatDt
control.DataBin dings.Add(bnd)
End Sub

Private Sub FormatDt(ByVal sender As Object, ByVal e As
System.Windows. Forms.ConvertEv entArgs)
e.Value = Format(e.Value, "D")
End Sub

hth,
greetings

When I run the app. the dates in the textboxes are formatted correctly,
however the textboxes are on a tab control and when I click onto a
different
tab and then back all the dates show in the format 01/01/2005 00:00:00.

Any ideas?

Nov 21 '05 #3

That's perfect.
Thank you Bart.
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1351
by: GMG | last post by:
By providing a DTD in an XML document which is bound to HTML controls, Internet Explorer will automatically format the display of the date fields. For example 2004-08-03T00:00:00 will be displayed as 08/03/2004. It is a fantastic feature, but how does it determine which format to display it in ? The format that is being displayed on the samples I am looking at does not match my regional settings. All the dates are displayed in US format...
3
3165
by: Kevin Swanson | last post by:
I'm writing what should be a very simple app against an Oracle database. The app has a number of user controls, any one of which is loaded into a main display page using the loadControl method, depending on which menu item a user selects. Each of these controls follows the same basic pattern: Get a dataset from the database and then display the results using basic databinding. Everything works fine except that I'll occaisionally get an...
8
2187
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got answered... In 1.1 we always did our own myDataAdapter.fills and we liked that control for lots of good reasons. Now the new DataSource (or is it a TableAdapter:Dataset) automatically fills the Gridview. How can we control that fill? In a...
5
12534
by: Mark R. Dawson | last post by:
Hi all, I may be missing something with how databinding works but I have bound a datasource to a control and everything is great, the control updates to reflect the state of my datasource when I update the datasource - awesome, but I have an issue with updating from a different thread. Here is my datasource, a person class that raises the PropertyChanged event: class Person : INotifyPropertyChanged {
9
2321
by: Nathan Sokalski | last post by:
I have a very simple UserControl which contains an Image and a Label, which I use to display an image with a caption. I am using this control inside a DataList, setting the two Public variables using attributes in the *.aspx page. Everything displays great for the initial load, but whenever I try to add or delete an item (I have controls to do this on the page), it does not seem to be recieving any values for the public variables. Here is...
1
16262
by: Owen Blacker | last post by:
I've spent loads of time Googling to try to work this one out and I'm sure it's something obvious. I get an InvalidOperationException reading "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control" when I start my page. Unless I'm missing something obvious, this is *not* the same issue as the "2-way databinding cascading lists" issue in...
3
2231
by: Matt Brown - identify | last post by:
Hello, I'm trying to figure out a method to look up by a range of dates, entries in a database. The format of the date in the database is "M\D \yyyy HH:MM:SS". What i need to do is take the dates that are in the database (formatted as above), isolate the date (which is in short format) and compare it to the short formatted date in a datetimepicker.
0
1136
by: opedog | last post by:
I'm monkeying around with databinding, trying to learn all the ins and outs. I'm populating a label from one of my business objects properties which is a string, however, I want some formatting done on the string first. I got this working using the binding's Format event. But, I want to go one step further. Instead of using the Format event, I'm trying to set the FormatString and FormatInfo properties to make the databinding go through the...
3
1835
by: mesut | last post by:
Hi colleagues, I hope someone have experience with these databinding techniques in aspx... and can explain me the reason? I've got a listview and I would like to fix these #3 problems just to learn how to do it... can someone help me what is wrong in my code? I won't get squeezed line or whatever.. so the syntax looks correct.
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10546
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10292
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7603
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.