473,383 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

connecting vb.net and ms access

1
hi sir,
i've a problem during odbc connection with vb.net and ms access
pls help me
send me the query syntax for insert, update, select, delete in vb.net to connect ms access using odbc connection
Jun 22 '14 #1
2 1394
You need to first create a database source using control panel and then add it to your VB.NET project.
Jun 22 '14 #2
ambusy
5
To create the ODBC database I execute: c:\WINDOWS\SysWOW64\odbcad32.exe
In the resulting window, on tab "User DSN"
- I add my database with name ArCatSy with attributes Microsoft Access Driver (*.mdb)
- Save and exit
In Visual basic I have this (partial) code:
Expand|Select|Wrap|Line Numbers
  1.     Dim DbConn As odbcConnection
  2.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  3.         SqlProv = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=ArCatSy.mdb"
  4.         DbConn = New odbcConnection(SqlProv)
  5.         ' Check db exists
  6.         Dim retr As MsgBoxResult
  7.         retr = MsgBoxResult.Retry
  8.         While retr = MsgBoxResult.Retry
  9.             Try
  10.                 DbConn.Open()
  11.                 DbConn.Close()
  12.                 retr = MsgBoxResult.Ok
  13.             Catch ex As Exception
  14.                 retr = MsgBox("No ArCatSy database?", MsgBoxStyle.RetryCancel)
  15.             End Try
  16.         End While
  17.         If retr = MsgBoxResult.Cancel Then
  18.             Me.Close()
  19.             Exit Sub
  20.         End If
  21.     End Sub
  22.     Private Sub OpenDb()
  23.         Try
  24.             DbConn.Open()
  25.         Catch ex As Exception
  26.             MsgBox(ex.ToString(), , "Open DB")
  27.         End Try
  28.     End Sub
  29.     ' put all PrtSpec's in a TreeNode
  30.     Private sub procSpecs
  31.         OpenDb()
  32.         Dim cSelectSQL As String = "SELECT PrtSpec FROM PrtSpecs WHERE CollCode = ? ORDER BY PrtSpec"
  33.         Dim DRcSelect As odbcDataReader = Nothing
  34.         Dim DbCcSelect As odbcCommand
  35.         Dim cSelP1 As New odbcParameter("@CollCode", odbc.odbcType.VarChar, 4)
  36.         DbCcSelect = New odbcCommand(cSelectSQL, DbConn)
  37.         DbCcSelect.Parameters.Add(cSelP1)
  38.         Try ' all prtspecs of my Collection
  39.             cSelP1.Value = CollCode
  40.             DRcSelect = DbCcSelect.ExecuteReader()
  41.             Do While (DRcSelect.Read())
  42.                 Dim prt As String = GetDbStringValue(DRcSelect, 0)
  43.                 PrtNode = New TreeNode(prt)
  44.                 PrtNode.Name = prt
  45.                 PrtNode.Checked = (prt = defPrt)
  46.                 CollCodeNode.Nodes.Add(PrtNode)
  47.             Loop
  48.             CollCodeNode.Expand()
  49.         Catch ex As Exception
  50.             MsgBox(ex.ToString())
  51.          Finally
  52.             If Not (DRcSelect Is Nothing) Then
  53.                DRcSelect.Close()
  54.             End If
  55.          End Try
  56.          DbConn.Close()
  57.     End Sub
  58.     ' insert some row
  59.     Private Sub InsRow(toData as TwInDb)
  60.         Dim SQLTwInsert As String = "INSERT INTO SearchTerms (CollCode, CollSeq, TermType, TermText) VALUES (?, ?, ?, ?)"
  61.         Dim DRTwInsert As odbcDataReader = Nothing
  62.         Dim DCCTwInsert As odbcCommand
  63.         Dim TwInsP1 As New odbcParameter("@CollCode", odbc.odbcType.VarChar, 4)
  64.         Dim TwInsP2 As New odbcParameter("@CollSeq", Odbc.OdbcType.Int, 4)
  65.         Dim TwInsP3 As New odbcParameter("@TermType", odbc.odbcType.VarChar, 4)
  66.         Dim TwInsP4 As New odbcParameter("@TermText", odbc.odbcType.VarChar, 255)
  67.         DCCTwInsert = New odbcCommand(SQLTwInsert, DbConn)
  68.         DCCTwInsert.Parameters.Add(TwInsP1)
  69.         DCCTwInsert.Parameters.Add(TwInsP2)
  70.         DCCTwInsert.Parameters.Add(TwInsP3)
  71.         DCCTwInsert.Parameters.Add(TwInsP4)
  72.         OpenDb()
  73.         TwInsP1.Value = CurCollCode
  74.         TwInsP2.Value = CollSeq
  75.         TwInsP3.Value = toData.FldTermTypec
  76.         TwInsP4.Value = toData.FldTermTypet
  77.         Try
  78.             DRTwInsert = DCCTwInsert.ExecuteReader()
  79.         Catch ex As Exception
  80.             MsgBox(ex.ToString(), , "Insert Term")
  81.         Finally
  82.             If Not (DRTwInsert Is Nothing) Then
  83.                 DRTwInsert.Close()
  84.             End If
  85.         End Try
  86.         DbConn.Close()
  87.     End Sub
  88.  
  89.  
For eac h type of data I have a function to retrieve the nth element of a cursorrow in it's correct format taking care of NULLs. 2 examples:
Expand|Select|Wrap|Line Numbers
  1.     <Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
  2.     Friend Function GetDbStringValue(ByVal Dr As odbcDataReader, ByVal nr As Integer) As String
  3.         If IsDBNull(Dr.Item(nr)) Then
  4.             Return ""
  5.         Else
  6.             Return Dr.GetString(nr).TrimEnd
  7.         End If
  8.     End Function
  9.  
  10.     <Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
  11.     Friend Function GetDbBooleanValue(ByVal Dr As odbcDataReader, ByVal nr As Integer) As Boolean
  12.         If IsDBNull(Dr.Item(nr)) Then
  13.             Return False
  14.         Else
  15.             Return Dr.GetBoolean(nr)
  16.         End If
  17.     End Function
  18.  
with a GET and an UPDATE example, you can figure out how to solve your code problems. Good Luck
Aug 18 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Krish | last post by:
Hi Friends, Does anyone know how to connect access database into Visual C++ in Visual Studio 6.0. I know the procedure to connect access database into Visual Studio .Net. But Visual Studio 6.0...
0
by: Rupe | last post by:
I have a web site on a remote, shared host with a bunch of individual Access databases. I want to switch my databases from Access to MS SQL and have some questions. I update some of my Access...
1
by: aperez | last post by:
I have an Access 97 database that I connect to a SQL Server 2000 through ODBC. I have to manually set up the ODBC connection on each user's machine if I want them to be able to use the application...
2
by: Guillermo | last post by:
Gentlemen, I have a VB6 Project. Works fine in my PC, but once uploaded to my website it can't connect to my Access database. Questions: 1. Can VB.net connect with Access 2003 databases hosted in...
2
by: bart van deun | last post by:
Hi everybody, Can someone tell me what are the possibilities for connecting Access to the web? Something like thirt party software to do that? Thank you, Someone from Belgium - Europe
1
by: Giel Overhof | last post by:
I am searching for code that makes it possible to connect a cash register (operated with microsoft Access 2003 software) with a PIN/CHIP payment divise. Can some of you give me futher information...
8
by: Bob Alston | last post by:
With all the recent discussions on ADPs and their lack of success, can someone point me to some GOOD reading on what is required to link MDBs to SQL Databases / Microsoft SQL Server 2000 Desktop...
1
by: Krish | last post by:
Hi Friends, Does anyone know how to connect access database into Visual C++ in Visual Studio 6.0. I know the procedure to connect access database into Visual Studio .Net. But Visual Studio 6.0...
4
by: Sticksboy | last post by:
I am totally new to ADO and I am wanting to connect an Access database to SQL Server database to bring back data tables. The SQL Server is on a Remote Desktop, and I dont want to just link the tables...
3
by: mehdi4467 | last post by:
Hi, I am trying to connecting Access DataBase to C#, my data base hase 3 table. in c# when I configure data adapter and run SELECT account.* FROM account query, there is no...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.