i'm using VB.NET
i have 4 computers in network.
when i press a button i need to delete a table from computer 2,3,4 and i need to copy that table from computer 1 to 2,3,4.
and this file is a table inside a .mdb file. so i can't use "FILECOPY(sOURCE,DESTINATION)".
Eg: if the path is "c:\Programs\data.mdb" ,then Emp is one of the table inside that data.mdb. and i don't need to delete entire data.mdb, i need to delete only that "Emp" table and i don't need to copy entire data.mdb, i need to copy only "Emp" table and save it in computers 2,3,4.
if anyone have anyidea how to delete and copy this table inside .mdb file, to other computers in network.
if you have any idea please let me know. and if you can provide eg: that will be great help for me.
thanks in advance.
4 1523
i tried this code....
Code
--------
Dim nPath As String = "\\t1\root\Programs"
Dim strConn1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & nPath & "\DataTables.mdb"
Dim strSQL1 As String = "Select * from Employees"
Dim myConnection1 As New OleDbConnection(strConn1)
myConnection1.Open()
Dim myCommand1 As New OleDbCommand(strSQL1, myConnection1)
Dim myReader1 As OleDbDataReader = myCommand1.ExecuteReader
While myReader1.Read
Dim nPath2 As String = "\\t2\root\Programs"
Dim strConn2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & nPath2 & "\Terminal.mdb"
Dim strSQL2 As String = "insert into Employees (EmpID, FirstName, LastName, AccessN0,CardNo,InsuranceNo) values (" & Trim(myReader1(0)) & ", '" & Trim(myReader1(1)) & "', '" & Trim(myReader1(2)) & "', " & Trim(myReader1(3)) & ", " & Trim(myReader1(4)) & ", " & Trim(myReader1(5)) & ", " & Trim(myReader1(6)) & ") "
Dim myConnection2 As New OleDbConnection(strConn2)
myConnection2.Open()
Dim myCommand2 As New OleDbCommand(strSQL2, myConnection2)
myCommand2.ExecuteNonQuery()
End While
myReader1.Close()
myConnection1.Close()
Sometimes some of the fields will be blank. and while trying to insert the values to computer 2 from computer 1 error occurs as
Error:
------
"An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll. Additional information: Cast from type 'DBNull' to type 'String' is not valid."
if anyone have anyidea what's wrong in my codes please help me.
thanks in advance.
Code:
Dim nPath As String = "\\t1\root\Programs"
Dim strConn1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & nPath & "\DataTables.mdb"
Dim strSQL1 As String = "Select * from Emp"
Dim myConnection1 As New OleDbConnection(strConn1)
myConnection1.Open()
Dim myCommand1 As New OleDbCommand(strSQL1, myConnection1)
Dim myReader1 As OleDbDataReader = myCommand1.ExecuteReader
While myReader1.Read
Dim nPath2 As String = "t2\\root\Programs"
Dim strConn2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & nPath2 & "\DataTable.mdb"
Dim strSQL2 As String = "insert into Emp (EmployeeID, EmployeePrivateAccessNumber,SwipeCardNumber,Social InsuranceNumber, FirstName, LastName, Title, Address, City, State, PostalCode, HomePhone, EmrgcyContactName, EmrgcyContactPhone, IsThisPersonAManager, OpenWhichCashDrawer, AccessToManagerScreen, AllowedToGiveDiscounts, AllowedToDeleteSentItems, AllowedToCompItems, AllowedToCashOut, AllowedToAccessOtherOrders, AllowedToChangeItems, AllowedToRunReports, AllowedToQuickCashOut, WhichMenuLevel, index, StartOnQuickScreen, HourlyWage, AllowedToTransferOrders, Dancer, StageName, Age, DepartmentID, ListStyle, AccessToServerSide, Driver, AccessToPrintSpooler, BusBoy, WhichRoom, AccessToHouseAccounts, ShareTips, JobCode1, JobCode2, JobCode3, JobCode4, JobCode5, JobCode6, JobCode7, JobCode8, JobCode9, JobCode10, JobCode1HourlyWage, JobCode2HourlyWage, JobCode3HourlyWage, JobCode4HourlyWage, JobCode5HourlyWage, JobCode6HourlyWage, JobCode7HourlyWage, JobCode8HourlyWage, JobCode9HourlyWage, JobCode10HourlyWage, Message, Cashier, TipOutToBarStaffOnLogOut, TipOutToKitchenStaffOnLogOut, AllowedToEmail, MultiSelectOnMainMenuList, RecordLogOutInfo, TrainingMode, InActive, Salaried, DeliveryDispatcher, ForceDrawer1_2, JobCodeProfile, CompValue, CashLimit, ServerKey, ClearviewKey, LanguagePreference, AccessLevel) " & _
"values ('" & CheckNull(Trim(myReader1(0))) & "', '" & CheckNull(Trim(myReader1(1))) & "', '" & Trim(myReader1(2)) & "', '" & CheckNull(Trim(myReader1(3))) & "', '" & CheckNull(Trim(myReader1(4))) & "', '" & CheckNull(Trim(myReader1(5))) & "', '" & CheckNull(Trim(myReader1(6))) & "', '" & CheckNull(Trim(myReader1(7))) & "', '" & CheckNull(Trim(myReader1(8))) & "', '" & CheckNull(Trim(myReader1(9))) & "', '" & CheckNull(Trim(myReader1(10))) & "', '" & CheckNull(Trim(myReader1(11))) & "', '" & CheckNull(Trim(myReader1(12))) & "', '" & CheckNull(Trim(myReader1(13))) & "', '" & CheckNull(Trim(myReader1(14))) & "', '" & CheckNull(Trim(myReader1(15))) & "', '" & CheckNull(Trim(myReader1(16))) & "', '" & CheckNull(Trim(myReader1(17))) & "', '" & CheckNull(Trim(myReader1(18))) & "', '" & CheckNull(Trim(myReader1(19))) & "', '" & CheckNull(Trim(myReader1(20))) & "', '" & CheckNull(Trim(myReader1(21))) & "', '" & CheckNull(Trim(myReader1(22))) & "', '" & CheckNull(Trim(myReader1(23))) & "', '" & CheckNull(Trim(myReader1(24))) & "', '" & CheckNull(Trim(myReader1(25))) & "', '" & CheckNull(Trim(myReader1(26))) & "', '" & CheckNull(Trim(myReader1(27))) & "', '" & CheckNull(Trim(myReader1(28))) & "', '" & CheckNull(Trim(myReader1(29))) & "', '" & CheckNull(Trim(myReader1(30))) & "', '" & CheckNull(Trim(myReader1(31))) & "', '" & CheckNull(Trim(myReader1(32))) & "', '" & CheckNull(Trim(myReader1(33))) & "', '" & CheckNull(Trim(myReader1(34))) & "', '" & CheckNull(Trim(myReader1(35))) & "', '" & CheckNull(Trim(myReader1(36))) & "', '" & CheckNull(Trim(myReader1(37))) & "', '" & CheckNull(Trim(myReader1(38))) & "', '" & CheckNull(Trim(myReader1(39))) & "', '" & CheckNull(Trim(myReader1(40))) & "', '" & CheckNull(Trim(myReader1(41))) & "', '" & CheckNull(Trim(myReader1(42))) & "', '" & CheckNull(Trim(myReader1(44))) & "', '" & CheckNull(Trim(myReader1(45))) & "', '" & CheckNull(Trim(myReader1(46))) & "', '" & CheckNull(Trim(myReader1(47))) & "', '" & CheckNull(Trim(myReader1(48))) & "', '" & CheckNull(Trim(myReader1(49))) & "', '" & CheckNull(Trim(myReader1(51))) & "', '" & CheckNull(Trim(myReader1(52))) & "', '" & CheckNull(Trim(myReader1(53))) & "', '" & CheckNull(Trim(myReader1(54))) & "', '" & CheckNull(Trim(myReader1(55))) & "', '" & CheckNull(Trim(myReader1(56))) & "', '" & CheckNull(Trim(myReader1(57))) & "', '" & CheckNull(Trim(myReader1(58))) & "', '" & CheckNull(Trim(myReader1(59))) & "', '" & CheckNull(Trim(myReader1(60))) & "', '" & CheckNull(Trim(myReader1(61))) & "', '" & CheckNull(Trim(myReader1(62))) & "', '" & CheckNull(Trim(myReader1(62))) & "', '" & CheckNull(Trim(myReader1(63))) & "', '" & CheckNull(Trim(myReader1(64))) & "', '" & CheckNull(Trim(myReader1(65))) & "', '" & CheckNull(Trim(myReader1(66))) & "', '" & CheckNull(Trim(myReader1(67))) & "', '" & CheckNull(Trim(myReader1(68))) & "', '" & CheckNull(Trim(myReader1(69))) & "', '" & CheckNull(Trim(myReader1(70))) & "', '" & CheckNull(Trim(myReader1(71))) & "', '" & CheckNull(Trim(myReader1(72))) & "', '" & CheckNull(Trim(myReader1(73))) & "', '" & CheckNull(Trim(myReader1(74))) & "', '" & CheckNull(Trim(myReader1(75))) & "', '" & CheckNull(Trim(myReader1(76))) & "', '" & CheckNull(Trim(myReader1(77))) & "', '" & CheckNull(Trim(myReader1(78))) & "', '" & CheckNull(Trim(myReader1(79))) & "', '" & CheckNull(Trim(myReader1(80))) & "') "
Dim myConnection2 As New OleDbConnection(strConn2)
myConnection2.Open()
Dim myCommand2 As New OleDbCommand(strSQL2, myConnection2)
myCommand2.ExecuteNonQuery()
End While
myReader1.Close()
myConnection1.Close()
myCommand1.Dispose()
Public Function CheckNull(ByVal Value As String) As String
If IsDBNull(Value) Then
Return ("")
ElseIf Value = "." Then
Return ("")
ElseIf Value = "" Then
Return ("")
Else
Return CStr(Value)
End If
End Function
and while running its passing through SQL. and that its taking vlues too. and i'm pasting that SQL taking values during run time here.
"insert into Emp (EmployeeID, EAccessNumber, ........etc) values (4192, 9, 112, ., 'Manager', 'Manager', '.', '.', '.', '.', '.', '.', '.', '.', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 78, 0, 0, 1, '0', ., 0, 1, 0, 0, 0, 0, 0, 302, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ., '.', 0, 0, 0, 1, 1, 2, 0, 0, 0, 0, 1, 0, 0, 0, 4, 300101, 0, 0) "
and when it reach this myCommand2.ExecuteNonQuery() line error occurs as below.
Error
-----
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
if anyone have anyidea what's the mistake i did in my codes, please let me know. please help me...
thanks in advance...
and i insert the TRy Catch in my codes.
Code:
Dim nPath As String = "\\t1\root\Programs"
Dim strConn1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & nPath & "\DataTables.mdb"
Dim strSQL1 As String = "Select * from Emp"
Dim myConnection1 As New OleDbConnection(strConn1)
myConnection1.Open()
Dim myCommand1 As New OleDbCommand(strSQL1, myConnection1)
Dim myReader1 As OleDbDataReader = myCommand1.ExecuteReader
While myReader1.Read
Dim nPath2 As String = "t2\\root\Programs"
Dim strConn2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & nPath2 & "\DataTable.mdb"
Try
Dim strSQL2 As String = "insert into Emp (EmployeeID, EmployeePrivateAccessNumber,SwipeCardNumber,Social InsuranceNumber, FirstName, LastName, Title, Address, City, State, PostalCode, HomePhone, EmrgcyContactName, EmrgcyContactPhone, IsThisPersonAManager,OpenWhichCashDrawer, AccessToManagerScreen, AllowedToGiveDiscounts, AllowedToDeleteSentItems, AllowedToCompItems, AllowedToCashOut, AllowedToAccessOtherOrders, AllowedToChangeItems, AllowedToRunReports, AllowedToQuickCashOut, WhichMenuLevel, StartOnQuickScreen, HourlyWage, AllowedToTransferOrders, Dancer, StageName, Age, DepartmentID, ListStyle, AccessToServerSide, Driver, AccessToPrintSpooler, BusBoy, WhichRoom, AccessToHouseAccounts, ShareTips, JobCode1, JobCode2, JobCode3, JobCode4, JobCode5, JobCode6, JobCode7, JobCode8, JobCode9, JobCode10, JobCode1HourlyWage, JobCode2HourlyWage, JobCode3HourlyWage, JobCode4HourlyWage, JobCode5HourlyWage, JobCode6HourlyWage, JobCode7HourlyWage, JobCode8HourlyWage, JobCode9HourlyWage, JobCode10HourlyWage, Message, Cashier, TipOutToBarStaffOnLogOut, TipOutToKitchenStaffOnLogOut, AllowedToEmail, MultiSelectOnMainMenuList, RecordLogOutInfo, TrainingMode, InActive, Salaried, DeliveryDispatcher, ForceDrawer1_2, JobCodeProfile, CompValue, CashLimit, ServerKey, ClearviewKey, LanguagePreference, AccessLevel) " & _
"values (" & EmpId & ", " & AccessNo & ", " & Cardno & ", '" & SINno & "', '" & FName & "', '" & LName & "', '" & eTitle & "','" & eAddress & "', '" & eCity & "', '" & eState & "', '" & ePin & "', '" & eHomePhone & "', '" & eEmyContactName & "', '" & eEmyContactPhone & "', " & isManager & ", " & eOpenCashDraw & ", " & ManagerScreen & ", " & GiveDiscount & ", " & delsend & ", " & eCompItem & ", " & eCashOut & ", " & eAccessOrder & ", " & eChangeitems & ", " & eRunReport & ", " & eQuickcashOut & ", " & eMenuLevel & ", " & eQuickscreen & ", " & eHourWage & ", " & eTransferOrder & ", " & eDance & ", '" & eStageName & "', " & eAge & ", " & eDepId & ", " & eListStyle & ", " & eServerSide & ", " & eDriver & ", " & ePrintSpooler & ", " & eBusBoy & ", " & eWhichRoom & ", " & eHouseAccount & ", " & Trim(myReader1(41)) & ", " & Trim(myReader1(42)) & ", " & Trim(myReader1(43)) & ", " & Trim(myReader1(44)) & ", " & Trim(myReader1(45)) & ", " & Trim(myReader1(46)) & ", " & Trim(myReader1(47)) & ", " & Trim(myReader1(48)) & ", " & Trim(myReader1(49)) & ", " & Trim(myReader1(50)) & ", " & Trim(myReader1(51)) & ", " & Trim(myReader1(52)) & ", " & Trim(myReader1(53)) & ", " & Trim(myReader1(54)) & ", " & Trim(myReader1(55)) & ", " & Trim(myReader1(56)) & ", " & Trim(myReader1(57)) & ", " & Trim(myReader1(58)) & ", " & Trim(myReader1(59)) & ", " & Trim(myReader1(60)) & ", " & Trim(myReader1(61)) & ", '" & emessage & "', " & Trim(myReader1(63)) & ", " & Trim(myReader1(64)) & ", " & Trim(myReader1(65)) & ", " & Trim(myReader1(66)) & ", " & Trim(myReader1(67)) & ", " & Trim(myReader1(68)) & ", " & Trim(myReader1(69)) & ", " & Trim(myReader1(70)) & ", " & Trim(myReader1(71)) & ", " & Trim(myReader1(72)) & ", " & Trim(myReader1(73)) & ", " & Trim(myReader1(74)) & ", " & Trim(myReader1(75)) & ", " & Trim(myReader1(76)) & ", " & Trim(myReader1(77)) & ", " & Trim(myReader1(78)) & ", " & Trim(myReader1(79)) & ", " & Trim(myReader1(80)) & ") "
Dim myConnection2 As New OleDbConnection(strConn2)
myConnection2.Open()
Dim myCommand2 As New OleDbCommand(strSQL2, myConnection2)
myCommand2.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(Err.Number & " - " & ex.Message)
End Try
Dim myConnection2 As New OleDbConnection(strConn2)
myConnection2.Open()
Dim myCommand2 As New OleDbCommand(strSQL2, myConnection2)
myCommand2.ExecuteNonQuery()
End While
myReader1.Close()
myConnection1.Close()
myCommand1.Dispose()
sometimes it take values from T1 and writes to T2. sometimes i get this error
"5 - Could not update; currently locked by user 'Admin' on machine 'T2'."
and before showing this error some of the records got saved in mdb. and ecah time the number of records enter in mdb before showing this error is random. sometime all the recorsd will be saved and it won't show this error too.
and database is not open while running the code. and no other calls are made to the database at that time too.
if you have any idea what's wrong in my codes please help me. and please let me know. please help me.
thanks in advance.
heah its working now......
that error occurs because myConnection2 is opening each time while its enter while loop but its not closing.
Thanks a lot for your help..... thanks a lot..... -
Dim nPath As String = "\\t1\root\Programs"
-
Dim strConn1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
-
"Data Source=" & nPath & "\DataTables.mdb"
-
-
Dim strSQL1 As String = "Select * from Emp"
-
Dim myConnection1 As New OleDbConnection(strConn1)
-
myConnection1.Open()
-
Dim myCommand1 As New OleDbCommand(strSQL1, myConnection1)
-
Dim myReader1 As OleDbDataReader = myCommand1.ExecuteReader
-
-
While myReader1.Read
-
Dim nPath2 As String = "t2\\root\Programs"
-
Dim strConn2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
-
"Data Source=" & nPath2 & "\DataTable.mdb"
-
-
Try
-
Dim strSQL2 As String = "insert into Emp (EmployeeID, ...... ) " & _
-
"values (" & EmpId & ", .....) "
-
Dim myConnection2 As New OleDbConnection(strConn2)
-
myConnection2.Open()
-
Dim myCommand2 As New OleDbCommand(strSQL2, myConnection2)
-
myCommand2.ExecuteNonQuery()
-
Catch ex As Exception
-
MessageBox.Show(Err.Number & " - " & ex.Message)
-
End Try
-
-
Dim myConnection2 As New OleDbConnection(strConn2)
-
myConnection2.Open()
-
Dim myCommand2 As New OleDbCommand(strSQL2, myConnection2)
-
myCommand2.ExecuteNonQuery()
-
myConnectio2.Close()
-
End While
-
-
myReader1.Close()
-
myConnection1.Close()
-
myCommand1.Dispose()
-
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ove |
last post by:
I have one Access 2000 DB on my website. I want to access these tables
from my local database so i do not need to down-/upload the database
each time i want to make changes.
Meanwhile i want a...
|
by: GiladP1 |
last post by:
Hi,
I want to copy protect my application. I want to limit its use for a
given period of time, say 30 days, after which a license key will be
needed.
There are various issues to consider here...
|
by: Ram Baruch |
last post by:
Hi,
I'm trying to use the File.Copy() function. It works well when the
desenation file is local (Like: C:\dest\dest.exe). The problem is that when
I'm trying to copy to a destenation that starts...
|
by: adnan boz |
last post by:
Hi All,
Does somebody know why File.Copy function is 10 times slower than standard
windows drag and drop copy between folders, when I copy files over the
network?
Actually, I need to copy files...
|
by: Paul Brady |
last post by:
I volunteer at a youth ministry agency and help them with their
student database. They have two computers, both running Windows XP.
Both have Office 2002 installed without Access, except that...
|
by: =?Utf-8?B?U2Vhbk1hYw==?= |
last post by:
How do I programmatically copy files across a network (from a local
workstation to another local workstation on the network) using visual basic
2005?
In other words, when in explorer and you enter...
|
by: Andy_Khosravi |
last post by:
I just recently changed my database that I'm running from a monolithic
DB to a split FE/BE. The front end resides on the client machine and
the BE resides on a network drive. I'm experimenting with...
|
by: rizwan6feb |
last post by:
Hello everybody. I need help on how to use copy function to copy file from one computer to another ( or any other way i can copy the file). The computers are on a local network.
|
by: Jason |
last post by:
I want to create a simple program with Two buttons on the form.
BUTTON 1 - BACKUP PREFS
this will do the following:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |