Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Inserting fields into a database from textboxes

Posted on 2002-04-25
11
Medium Priority
?
158 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
[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
  • 2
  • +1
11 Comments
 

Expert Comment

by:dsplice
ID: 6969677
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
ID: 6969706
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
ID: 6969707
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:dsplice
ID: 6969777
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
ID: 6969953
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
 
LVL 16

Expert Comment

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

Accepted Solution

by:
Death-Speak earned 200 total points
ID: 6969985
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
ID: 6970364
Death-Speak, thanks for your support.
0
 

Expert Comment

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

Author Comment

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

Expert Comment

by:Richie_Simonetti
ID: 6978690
:0
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

721 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