AllExperts > Experts 
Search      

VB.NET

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB.NET Answers
Question Library

Ask a question about VB.NET
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Stephen Jackson
Expertise
I can help with questions regarding VB.NET syntax and object references, with data interfaces and with the design and creation of robust, data aware object classes. I can also be very helpful with creating distributable applications and provide tricks and tips on .msi creation. I also have extensive experience in designing SQL Server Databases and interfacing them with VB.NET. I try to avoid web specific questions, as that is an area of expertise all its own.

Experience

Experience in the Area:
I have been a programmer in Visual Basic since version 1.0 and have worked with VB.NET (which is infinitely more powerful than previous versions) since its initial release and SQL Server, both as a corporate IT professional and professional consultant. I first wrote Basic in 1976 on a TRS 80 and have worked in Visual Basic 1.0 and every subsequent release of Microsoft Visual Basic. I worked for over 7 years as a Senior Level Consultant in the area and currently hold a Project Manager position in IT.

Education and Credentials:
MBA in Econometrics, 1983, University of Memphis. BBA in Financial Management, 1982, Fogelman College of Business and Economics, University of Memphis.
Microsoft Certified Professional

Areas of Special Expertise:
My specialty is the design of Object Oriented Solutions with robust, data aware object classes. I generally avoid the classic ‘Three Tier’ model as I find it redundant and cumbersome to maintain. I also specialize in the creation of ‘User Friendly’ User Interfaces which help lessen the need for user training and help prevent user error. I work best with Windows Forms based applications, and while I do work in C# as well, I prefer to limit my questions here to Windows Forms based applications created in Visual Basic.NET and SQL Server. I wil also address questions relating to the distribution and installation of Windows Forms based applications created in VB.NET.
 
   

You are here:  Experts > Computing/Technology > Basic > VB.NET > update command

Topic: VB.NET



Expert: Stephen Jackson
Date: 3/18/2008
Subject: update command

Question
my update command works just fine and i have three fields that represents double because they are number fields and in my database i gave them a default value of 0. but when i change those values an error occurs saying something like data truncate on that field. here's my update code by the way:

Dim myquery As New MyClasslibrary.MyHelper
       Form3.connect(myquery)

       Dim freeserv As Integer = 0

       If CheckBox1.Checked Then
           freeserv = 1
       Else
           freeserv = 0
       End If

       With myquery
           Dim id As String = ""

           .runQuery(" UPDATE tbltrcclient tc SET Lastname = '" & TextBox3.Text & "', Firstname = '" & TextBox4.Text & "', " _
           & " tc.Barangay = '" & ComboBox1.Text & "' " _
           & " where tc.ClientID = '" & TextBox1.Text & "' ")

           .runQuery(" Update tbltrcservice ts set Date = '" & DateTimePicker1.Value.ToString("yyyy-MM-dd") & "' , `Sitio/Purok` = '" & TextBox5.Text & "', ts.Barangay = '" & ComboBox2.Text & "', " _
           & " NatureofService = '" & ComboBox3.Text & "', NoOfHectares = '" & TextBox7.Text & "', NoOfLiters = '" & TextBox9.Text & "', " _
           & " TotalAmount = '" & TextBox11.Text & "', Free =  '" & freeserv.ToString & "', AmountPaid = '" & TextBox12.Text & "', " _
           & " AmountRemaining = '" & TextBox13.Text & "', Remarks = '" & TextBox14.Text & "' where ts.ClientID = '" & TextBox1.Text & "' ")

           MessageBox.Show("Data Updated.")

       End With

my double fields are TotalAmount, AmountPaid and AmountRemaining. can anyone help how to get rid of the error?


Answer
Enrico,

This one will come up a lot.  I recently fought with such an error only to finally realize I had entered my update fields in the wrong order!  Your situation is probably more subtle.  .NET and SQL Server are very sensitive to data type and size so first we will look at the obvious.  

Be sure your freeserve to string is not actually returning 'TRUE' or 'FALSE', for example. I am guessing by your code that this is being saved as a string, probably one character?  You might set up your variable as a string and set it to 'Y' or 'N'.... in fact, this is the very first thing I would try here!  

You need to check the field size for your text fields.  Then add a limit to your code (such as a trims and maybe a left function to only allow the maximum size string) to be sure your strings are not too large for the destination field.  Also make sure you are not sending an integer to a smaller size numeric field.  

Also check your dates to be sure you are not passing a date with a time to a short date field.  finally be sure your calculated values are not exceeding the allowable sizes of your destination table fields.  A little experimentation will probably reveal the culprit and once revealed, you will probably find it easy to correct.  I would look first at that

I hope this helps!  If not feel free to let me know and we will try again!

Thanks, and good luck!

Stephen Jackson

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.