Solved

Inserting fields into a database from textboxes

Posted on 2002-04-25
11
153 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

839 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