[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

VB.net Binding Controls to BindingSource with Formatting

Posted on 2014-02-06
7
Medium Priority
?
891 Views
Last Modified: 2014-02-18
Hi,

I am creating a database application and have bound my form controls to the binding source.

One of the form controls is a DateTimePicker and the DataBinding is:
dtpickerDate.DataBindings.Add("Value", bsReading, "Reading_Date", True, DataSourceUpdateMode.OnValidation, DateTime.Today)

Open in new window


How can I format the DataBinding so that when the value is sent back to the database it does not include the current timestamp or the current timestamp is set to 00:00:00.

I am using a DataAdapter to to insert/update the data.

Thanks, Greg
0
Comment
Question by:spen_lang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39838458
0
 

Author Comment

by:spen_lang
ID: 39839312
Hi,

Another formatting issue with a bound textbox, I would like to format the following as two decimal palces (rounded up).

How can I achieve this?

 txtUsage_TTM_CostDaily.DataBindings.Add("Text", bsUsage, "TTM_AvgDailyCost")

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39839692
Again, you can use Validating or TextChange event of Textbox.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:spen_lang
ID: 39841274
Hi,

I have tried the following code:
Private Sub txtUsage_InServ_CostDaily_TextChanged(sender As Object, e As System.EventArgs) Handles txtUsage_InServ_CostDaily.TextChanged
        txtUsage_InServ_CostDaily.Text = Convert.ToInt32(txtUsage_InServ_CostDaily.Text)
    End Sub

Open in new window


but I get an error, "Input string was not in a correct format."
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39842681
What does the textbox contain when you this code runs?

Try

Private Sub txtUsage_InServ_CostDaily_TextChanged(sender As Object, e As System.EventArgs) Handles txtUsage_InServ_CostDaily.TextChanged
If Not String.IsNullOrEmpty(txtUsage_InServ_CostDaily.Text) Then
        txtUsage_InServ_CostDaily.Text = Convert.ToInt32(txtUsage_InServ_CostDaily.Text)
End If
    End Sub

Open in new window

0
 

Accepted Solution

by:
spen_lang earned 0 total points
ID: 39843824
I have found out that you can setting the format when you bind the text box using
txtUsage_InServ_Cost.DataBindings.Add("Text", bsUsage, "RunningTotal_Cost", True, DataSourceUpdateMode.Never, vbNullString, "c5")

Open in new window

0
 

Author Closing Comment

by:spen_lang
ID: 39866932
resolved issue myself
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question