Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

Inserting fields into a database from textboxes

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
jackjeckyl
Asked:
jackjeckyl
  • 4
  • 3
  • 2
  • +1
1 Solution
 
dspliceCommented:
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
 
jackjeckylAuthor Commented:
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
 
jackjeckylAuthor Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
dspliceCommented:
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
 
jackjeckylAuthor Commented:
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
 
Richie_SimonettiCommented:
Could you replace txtDate.Text
with "" & txtDate.Text  and so on?
0
 
Death-SpeakCommented:
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
 
Richie_SimonettiCommented:
Death-Speak, thanks for your support.
0
 
Death-SpeakCommented:
LOL, sorry about the repeat, didn't realise I was replying for 7 or more minutes.
0
 
jackjeckylAuthor Commented:
I like the zero idea, works perfect, thanks!
0
 
Richie_SimonettiCommented:
: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.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now