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
2 1394
You need to first create a database source using control panel and then add it to your VB.NET project.
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: - Dim DbConn As odbcConnection
-
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
SqlProv = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=ArCatSy.mdb"
-
DbConn = New odbcConnection(SqlProv)
-
' Check db exists
-
Dim retr As MsgBoxResult
-
retr = MsgBoxResult.Retry
-
While retr = MsgBoxResult.Retry
-
Try
-
DbConn.Open()
-
DbConn.Close()
-
retr = MsgBoxResult.Ok
-
Catch ex As Exception
-
retr = MsgBox("No ArCatSy database?", MsgBoxStyle.RetryCancel)
-
End Try
-
End While
-
If retr = MsgBoxResult.Cancel Then
-
Me.Close()
-
Exit Sub
-
End If
-
End Sub
-
Private Sub OpenDb()
-
Try
-
DbConn.Open()
-
Catch ex As Exception
-
MsgBox(ex.ToString(), , "Open DB")
-
End Try
-
End Sub
-
' put all PrtSpec's in a TreeNode
-
Private sub procSpecs
-
OpenDb()
-
Dim cSelectSQL As String = "SELECT PrtSpec FROM PrtSpecs WHERE CollCode = ? ORDER BY PrtSpec"
-
Dim DRcSelect As odbcDataReader = Nothing
-
Dim DbCcSelect As odbcCommand
-
Dim cSelP1 As New odbcParameter("@CollCode", odbc.odbcType.VarChar, 4)
-
DbCcSelect = New odbcCommand(cSelectSQL, DbConn)
-
DbCcSelect.Parameters.Add(cSelP1)
-
Try ' all prtspecs of my Collection
-
cSelP1.Value = CollCode
-
DRcSelect = DbCcSelect.ExecuteReader()
-
Do While (DRcSelect.Read())
-
Dim prt As String = GetDbStringValue(DRcSelect, 0)
-
PrtNode = New TreeNode(prt)
-
PrtNode.Name = prt
-
PrtNode.Checked = (prt = defPrt)
-
CollCodeNode.Nodes.Add(PrtNode)
-
Loop
-
CollCodeNode.Expand()
-
Catch ex As Exception
-
MsgBox(ex.ToString())
-
Finally
-
If Not (DRcSelect Is Nothing) Then
-
DRcSelect.Close()
-
End If
-
End Try
-
DbConn.Close()
-
End Sub
-
' insert some row
-
Private Sub InsRow(toData as TwInDb)
-
Dim SQLTwInsert As String = "INSERT INTO SearchTerms (CollCode, CollSeq, TermType, TermText) VALUES (?, ?, ?, ?)"
-
Dim DRTwInsert As odbcDataReader = Nothing
-
Dim DCCTwInsert As odbcCommand
-
Dim TwInsP1 As New odbcParameter("@CollCode", odbc.odbcType.VarChar, 4)
-
Dim TwInsP2 As New odbcParameter("@CollSeq", Odbc.OdbcType.Int, 4)
-
Dim TwInsP3 As New odbcParameter("@TermType", odbc.odbcType.VarChar, 4)
-
Dim TwInsP4 As New odbcParameter("@TermText", odbc.odbcType.VarChar, 255)
-
DCCTwInsert = New odbcCommand(SQLTwInsert, DbConn)
-
DCCTwInsert.Parameters.Add(TwInsP1)
-
DCCTwInsert.Parameters.Add(TwInsP2)
-
DCCTwInsert.Parameters.Add(TwInsP3)
-
DCCTwInsert.Parameters.Add(TwInsP4)
-
OpenDb()
-
TwInsP1.Value = CurCollCode
-
TwInsP2.Value = CollSeq
-
TwInsP3.Value = toData.FldTermTypec
-
TwInsP4.Value = toData.FldTermTypet
-
Try
-
DRTwInsert = DCCTwInsert.ExecuteReader()
-
Catch ex As Exception
-
MsgBox(ex.ToString(), , "Insert Term")
-
Finally
-
If Not (DRTwInsert Is Nothing) Then
-
DRTwInsert.Close()
-
End If
-
End Try
-
DbConn.Close()
-
End Sub
-
-
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: - <Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
-
Friend Function GetDbStringValue(ByVal Dr As odbcDataReader, ByVal nr As Integer) As String
-
If IsDBNull(Dr.Item(nr)) Then
-
Return ""
-
Else
-
Return Dr.GetString(nr).TrimEnd
-
End If
-
End Function
-
-
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
-
Friend Function GetDbBooleanValue(ByVal Dr As odbcDataReader, ByVal nr As Integer) As Boolean
-
If IsDBNull(Dr.Item(nr)) Then
-
Return False
-
Else
-
Return Dr.GetBoolean(nr)
-
End If
-
End Function
-
with a GET and an UPDATE example, you can figure out how to solve your code problems. Good Luck
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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$) {
}
...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |