Solved

Putting data into access database from visual basic program

Posted on 2006-11-08
6
210 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 109
ejb wildfly example 2 17
What does != "" mean in programming 8 77
Vector, list Questions R 6 31
This is about my first experience with programming Arduino.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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 …

809 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