Solved

Putting data into access database from visual basic program

Posted on 2006-11-08
6
206 Views
Last Modified: 2010-04-16
What I have is a program for checking leaks. The user inputs the pressures and temps and calcs the difference and displays this to the user. What I want to do is on the form the users fills in serial number and a couple other fields including pressures and temperatures and then pushes the calc button. When the button is pushed it calcs the difference and inputs all the information into a database.

Is this possible?
0
Comment
Question by:Kirius
6 Comments
 
LVL 2

Expert Comment

by:jay_s5
ID: 17901931
Yes, it is definitely possible. The easy part--once you know how to do it--is building the program.

What you are describing is using an Access backend for a Visual Basic application. An alternative would be to use VB code in Access to build an Access application to do the same thing.

The hard part is packaging the program and installing it on a user's machine because you will be dealing with issues regarding Microsoft's Data Access Components (MDAC) that are absent on some Windows 98 and earlier machines, and present, but with differing versions on Windows XP machines. The Packaging and Deployment Wizard in VB is not very helpful when it comes to the installation of the MDAC, so you have to resort to C++ scripts with Windows Studio Installer or another installation tool. If you know you will only be dealing with Windows XP machines, you may get away without hassling with an MDAC update/installation.

As an alternative to the VB/Access route, which would involve installing a program on all the users' machines, I would suggest using PHP and MySQL via a website to run your program. That way, it will work on Windows and Mac, there won't be any software to install, and your users can access the program from any internet-capable device.
0
 

Expert Comment

by:shwaqar82
ID: 17903631
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data.OleDb" %>  


That means we will use VB as the default coding language and we are going to use OLEDB .NET data provider. Now, here's the code for doing simple query using ADO.NET

<script language="vb" runat="server">

Sub Page_Load(sender as Object, e as EventArgs)
  'Get the Database Path, to be used in DB Connection String
  Dim sDBPath As String = Request.MapPath(".") & "\NWind.mdb"

  'Define DB Connection String
  Dim sCnnString As String = "Provider=Microsoft.Jet.Oledb.4.0;" & _
                             "Data Source=" & sDBPath

  'Define variables as input for our sql query
  Dim temperature As String  = txtTemp.Text.ToString
  Dim difference As String = txtDifference.Text.ToString
  Dim pressure As String = txtPressure.Text.ToString

  'Populate Connection Object
  Dim oCnn As New OleDbConnection(sCnnString)

  'Define our sql query
  Dim sSQL As String = "insert into tablename
(differene, pressure, temperature)
values ('Argos', 'Indiana', '89', '46501');"

  'Populate Command Object
  Dim oCmd As New OledbCommand(sSQL, oCnn)

Try

'Opening Connection for our DB operation  
oCnn.Open()

'Execute the query
oCmd.ExecuteNonQuery()

  Finally

    'Closing the data reader & connection object
    drEmployee.Close()
    oCnn.Close()
   
  End Try
End Sub
</script>

 i dunno what kind od code and fileds ur using

0
 
LVL 1

Author Comment

by:Kirius
ID: 17908608
Well actually what I have is a form with the text boxes of SerialNumber Retest EmpNumber StartPSi EndPSI StartTemp EndTemp LeakLocation, once these are filled it it does a calculation to see whether or not there is a leak. Once this is done I want this information placed into an access database. Maybe this helps a little more. Just 1 table corresponding to those txt boxes and a label named Time.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 4

Accepted Solution

by:
tobydavid earned 125 total points
ID: 17914269
This would be the general routine for the calc button:


Private Sub CalcBtn_Click()
Dim db As Database
Dim tb As TableDef
Dim rs As Recordset
‘*** Perform Calulation ***
‘ ….
‘*** Update Data Table ***
Set db = OpenDatabase("D:\...\....mdb")  ' Your dataset path an name
Set tb = db.TableDefs("YourTableName")
Set rs = tb.OpenRecordset
On Error Resume Next
rs.MoveLast
rs.AddNew
rs.Fields("FieldName1") = Value1
rs.Fields("FieldName2") = Value2
rs.Fields("FieldName3") = Value3
rs.Update
rs.Bookmark = rs.LastModified
rs.Close
db.Close

End Sub
0
 
LVL 1

Author Comment

by:Kirius
ID: 17914661
tobydavid Worked perfectly was exactly what I was looking for.
0
 
LVL 4

Expert Comment

by:tobydavid
ID: 17914682
Great.  Glad to have helped.

TB
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

707 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

13 Experts available now in Live!

Get 1:1 Help Now