Solved

Inserting fields into a database from textboxes

Posted on 2002-04-25
11
151 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
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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

863 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

24 Experts available now in Live!

Get 1:1 Help Now