Solved

Inserting fields into a database from textboxes

Posted on 2002-04-25
11
150 Views
Last Modified: 2012-05-04
I have a vb program that inserts data into a database based on whats in the text boxes.  Some of the boxes do not need data and can be left blank.  The table requires a value and instead of having a huge if...else statement that populates the fields with zeros (where there aren't values) I would like a quicker way.  Any ideas?  Either database (SQL Server 7.0) or at the VB level.  Just a pain in the butt.
0
Comment
Question by:jackjeckyl
  • 4
  • 3
  • 2
  • +1
11 Comments
 

Expert Comment

by:dsplice
Comment Utility
COuld you clarify a bit more. What is the scale of the VB application? Large? Small? Academic? If some fields will not have data entered into them, it should not be a large stretch to set the colums in the DB to allow nulls, In SQL Server 7.0 its a check box when in table design mode.  On the VB end of things, you can do a check for a empty string when you do your update, like
if text1.text = " " Then text1.text = blank


Or something to that affect

Let me know if thats clear

Dsplice


0
 

Author Comment

by:jackjeckyl
Comment Utility
Those columns in SQL 7 do allow nulls.  I am using one insert statement (Insert into table values ( ...)).  Whenever there is a blank box there will be just a blank space.  The "if" statement you referred to is exactly what I'm trying to avoid.  I'm hoping there's a quicker way.  We're talking like 30 some boxes here.
0
 

Author Comment

by:jackjeckyl
Comment Utility
Those columns in SQL 7 do allow nulls.  I am using one insert statement (Insert into table values ( ...)).  Whenever there is a blank box there will be just a blank space.  The "if" statement you referred to is exactly what I'm trying to avoid.  I'm hoping there's a quicker way.  We're talking like 30 some boxes here.
0
 

Expert Comment

by:dsplice
Comment Utility
Sorry about that, the answer I gave was supposed to be a comment.  

If you have allowed nulls set, you should be able to insert null values into the field.  If not, there may be something wrong with your coding so you might want to check that.

Doug


0
 

Author Comment

by:jackjeckyl
Comment Utility
Here's what I have for the insert statement in vb.

sProductivitySQL = "Insert into ProductivityData values ('" & txtDate.Text & "','" & cboOperatorNumberData.Text & "','" & _
    lblWorkgroupChanges.Caption & "','" & lblShiftChanges.Caption & "'," & txtBatLogonItems.Text & "," & _
    txtBatLogItemsHours.Text & "," & txtBatchesLogOn.Text & "," & txtBatchesLogOnHours.Text & "," & _
    txtDataEntryItems.Text & "," & txtDEItemsHours.Text & "," & txtDEKeystrokes.Text & "," & _
    txtDataEntryVerifyItems.Text & "," & txtDEVerifyItemsHours.Text & "," & txtDEVerifyKeystrokes.Text & "," & _
    txtItemsEncoded.Text & "," & txtItemsEncHours.Text & "," & txtMailItemsSorted.Text & "," & _
    txtSafeDepositItems.Text & "," & txtSafeDepositHours.Text & "," & txtReassociatedBatches.Text & "," & _
    txtReassociatedBatches.Text & "," & txtNoChecksEnclosed.Text & "," & txtOutgoingMailDistribution.Text & "," & _
    txtWaitHours.Text & "," & txtBreaks.Text & "," & txtOtherProcessingHours.Text & ")"
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Could you replace txtDate.Text
with "" & txtDate.Text  and so on?
0
 

Accepted Solution

by:
Death-Speak earned 50 total points
Comment Utility
Concatenate a "" (empty string) on to each text field being input and a "0" (or 0+ ) (zero) to each numerical value. That way no matter what you'll have a valid "value" for each input.

I'm not familiar with SQL (I use Oracle) but do you not have a default value that you can set for each field.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Death-Speak, thanks for your support.
0
 

Expert Comment

by:Death-Speak
Comment Utility
LOL, sorry about the repeat, didn't realise I was replying for 7 or more minutes.
0
 

Author Comment

by:jackjeckyl
Comment Utility
I like the zero idea, works perfect, thanks!
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
:0
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now