Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send variable contents to SQL server table

Status
Not open for further replies.

bryandj23

IS-IT--Management
Aug 18, 2003
105
US
Hello All.

I have a VB application that I'm working on that reads in data from a serial port. Currently, the app is designed to take in the data, display in a text box, and also dump to a text file. I further incorporated routines to break the data up into seperate variables. All of this is working correctly.

What I would like to do is put the contents of the variables into a table on my MSSQL server (2k). I've been looking all over for simple instructions or how-to's of how to create the ADO connection (I've seen many programming examples, but haven't tried any as of yet), and to simply INSERT the variables into the table.

To make this easier, let's say I have 8 variables, var(1) through var(8).

My database table is already created (using SQL administrator), so I'm thinking the inserting should be relatively simple?

Any samples or referrences to the code I need (and maybe a bit of explanation) would be greatly appreciated.

Thanks very much in advance.

Bryan Fulkersin
 
Playing with this a bit further, I'm going about changing my Duration and TalkTime variables from varchar to decimal(8,3). Reason being is I need to do some math in my reporting; I figured using decimal values for minutes would be a heck of alot easier.

In my VB program, I'm converting the time over to decimal. (Example from program's log file: Converted Duration to 1.583333). I'm using the datatype "Single" in VB.

I changed my table and stored procedure to reflect the changes to a decimal datatype. Also changed my commands in my VB program:

Code:
Public Function InsertCall(ByVal CallType As String, ByVal CallDate As String, ByVal CallTime As String, ByVal CalledNumber As String, ByVal CallTag As String, ByVal ConvDuration As Single, ByVal LineNum As Integer, ByVal Extension As Integer, ByVal Account As String, ByVal ConvTalkTime As Single) As Long

Call oCommand.Parameters.Append(oCommand.CreateParameter("Duration", adDecimal, adParamInput, 5, ConvDuration))
 Call oCommand.Parameters.Append(oCommand.CreateParameter("TalkTime", adDecimal, adParamInput, 5, ConvTalkTime))

When my program attempts to insert the record into SQL, I get a "The precision is invalid" error. In query analyzer, I am able to manually insert through the stored procedure.

Code:
InsertCall 'C', '20070627', NULL, '19897373331', '*', '0.5166667', '8104', '110', NULL, '1.301'

I'm thinking it has something to do with the datatypes in my VB program, however I can't figure out which type will coinside best with SQL.

I'm stuck (again)! Anyone with a quick resolution?

Thanks very much!
 
Nevermind! Problem solved!

I had to add:

Code:
.Precision = 8
.NumberScale = 3

to my VB app.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top