Solved

Inputing Into SQL DB from Visual 2003 App

Posted on 2006-06-20
2
230 Views
Last Modified: 2010-04-17
I'm a VB 6.0 programmer that is used to using commands such as the ones shown below.  I'm trying to take baby steps so all I want to do now is create a simple form and enter the information into a single table within a SQL DB located on my laptop.  Are there any easy tutorials or examples I can cheat off of to learn how to do this?  

Const provider As String = "Provider=SQLOLEDB;Data Source=servername;Initial Catalog=tablename;Integrated Security=SSPI;"
Public cn As ADODB.Connection

Dim variablename As New ADODB.Recordset

Public Sub opendatabase()
    On Error GoTo error
   
    Set cn = New ADODB.Connection
    cn.ConnectionString = provider
    cn.Open
    Exit Sub

error:
    Dim errloop, errcol
    Set errcol = cn.Errors
    MsgBox provider
    For Each errloop In errcol
        MsgBox errloop.Description & vbCrLf
    Next
End Sub

0
Comment
Question by:clebo99
2 Comments
 
LVL 7

Accepted Solution

by:
Clever_Bob earned 500 total points
ID: 16948388
Gidday clebo99, looks like you are going pretty well here

You just need to drop the info into SQL Server now, something like this....

qlStr="Insert Into MyTable (Fld1, Fld2, Fld3) Values ('" & Text1.Text & "','" & Text2.Text & "'," & iif(Text3.Text & "" = "","NULL","'"&Text3.Text&"'")  & ")"

cn.execute(qlStr)

Hope this helps!
0
 

Author Comment

by:clebo99
ID: 16950666
Thanks......I guess what I am confused about is the initial setup of the DB connection within the code.  Remember, I'm really used to VB 6 and am trying to transition to VB 2003.  The above code is exactly how I would do this in VB6 and I'm hoping it's just as close in VB 2003, although the book I have (that learn VB in 21 days) doesn't make it very clear on how to set this us.

The error I seem to be getting in VB 2003 is with the variable declaration of the ADODB connection.  It doesn't seem to understand that.  

The way I learn (fortunately or unfortunately) is to see a simple example and then run with it.   I am really hoping that it is as easy (maybe easy isn't the right word.  How about "the same") as in VB 6.0 where I can declare my DB connections, write a simple "OPEN DB" Procedure and perform simplified INSERT/UPDATE queries to the DB.

Does anyone have a quick "cheat sheet" on what the initial "setup" in the code would be for this?  

Chris

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

Title # Comments Views Activity
countX 22 82
changePi Challenge 15 104
topping2 challenge 13 82
Hello Experts, Below query is not working on oracle. It works in SQL Server 2008. I am facing errors. 2 15
A short article about a problem I had getting the GPS LocationListener working.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

21 Experts available now in Live!

Get 1:1 Help Now