Hello,I am trying to update records in my database from excel data using vbaeditor within excel.In order to launch a query, I use SQL langage in ADO as follwing:------------------------------------------------------------Dim adoConn As ADODB.ConnectionDim adoRs As ADODB.RecordsetDim sConn As StringDim sSql As StringDim sOutput As StringsConn = "DSN=MS Access Database;" & _"DBQ=MyDatabasePath;" & _"DefaultDir=MyPathDirectory;" & _"DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;" &_"PWD=xxxxxx;UID=admin;"ID, A, B C.. are my table fieldssSql = "SELECT ID, `A`, B, `C being a date`, D, E, `F`, `H`, I, J,`K`, L" & _" FROM MyTblName" & _" WHERE (`A`='MyA')" & _" AND (`C`>{ts '" & Format(Date, "yyyy-mm-dd hh:mm:ss") & "'})"& _" ORDER BY `C` DESC"Set adoConn = New ADODB.ConnectionadoConn.Open sConnSet adoRs = New ADODB.RecordsetadoRs.Open Source:=sSql, _ActiveConnection:=adoConnadoRs.MoveFirstSheets("Sheet1").Range("a2").CopyFromRecordset adoRsSet adoRs = NothingSet adoConn = Nothing---------------------------------------------------------------Does Anyone know How I can use the UPDATE, DELETE INSERT SQL statementsin this environement? Copying SQL statements from access does not workas I would have to reference Access Object in my project which I do notwant if I can avoid. Ideally I would like to use only ADO system andSQL approach.Thank you very muchNono
using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.OleDb; using System.Collections;
namespace TimeTracking.DB { public class sql { OleDbConnection conn;
// //the constructor for this class, set the connectionstring // public sql() { DBConnectionstring ConnectToDB = new DBConnectionstring(); conn = ConnectToDB.MyConnection(); }
// // // public void UpdateEntry(int ID, string Week, string Year, string Date, string Project, string Action, string Time, string Comment) { int m_ID = ID; int m_Week = (Convert.ToInt32(Week)); int m_Year = (Convert.ToInt32(Year)); string m_Date = Date; string m_Project = Project; int m_ProjectID = new int(); string m_Action = Action; int m_ActionID = new int(); Single m_Time = (Convert.ToSingle(Time)); string m_Comment = Comment;
// //get the project ID from the database and store it in m_ProjectID // OleDbCommand SelectProjectID = new OleDbCommand("SELECT tblProject.ProjectID FROM tblProject" + " WHERE (((tblProject.Project) LIKE @Project))", conn);
// //get the action ID from the database and store it in m_ActionID // OleDbCommand SelectActionID = new OleDbCommand("SELECT tblAction.ActionID FROM tblAction" + " WHERE (((tblAction.Action) LIKE @Action))", conn);
finally { //close the connection if (conn != null) { conn.Close(); } } } } }
Code Snippet
The update statement is not working in my application, no error in C# and no error in ms-access. When I paste the update query into the ms-access query tool and replace the parameter values (@....) with real values, is will update the record.
The following is my code for Access... can someone help me convert it to sql: My Connectionstring is "server=(local);database=Database;trusted_connection=true"
<%@ Page Language="VB" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <script language="VB" runat="server"> Sub btnLogin_OnClick(Src As Object, E As EventArgs) Dim myConnection As OleDbConnection Dim myCommand As OleDbCommand Dim intUserCount As Integer Dim strSQL As String strSQL = "SELECT COUNT(*) FROM tblLoginInfo " _ & "WHERE username='" & Replace(txtUsername.Text, "'", "''") & "' " _ & "AND password='" & Replace(txtPassword.Text, "'", "''") & "';" myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _ & "Data Source=" & Server.MapPath("login.mdb") & ";") myCommand = New OleDbCommand(strSQL, myConnection) myConnection.Open() intUserCount = myCommand.ExecuteScalar() myConnection.Close() If intUserCount > 0 Then lblInvalid.Text = "" FormsAuthentication.SetAuthCookie(txtUsername.Text, True) Response.Redirect("login_db-protected.aspx") Else lblInvalid.Text = "Sorry... try again..." End If End Sub </script>
Dear All, I would like to convert from Access To SQL DB undervisual Studio.Net 2005... How can I do it easily, or if there any software to do this automaticlly, please your help.. Awaiting your valuable reply. Many thanks in advance for your cooperation and continuous support....
I am currently in the process of writing an application to convert an Access database to SQL. Basically, I have created an odbc link in access and then I transfer the data from the access table to the linked table.
The problem is where I have to transfer the Identity keys. I can transfer all the data but the keys. They will auto increment. I tried using INSERT_IDENTITY tablename ON but it just returns an error mosty of the time. I have gotten it to transfer once or twice by stepping through.
Here is the basic code:
The code that causes everything to error is commented out.
Private Sub CopySQLRecordSet(ByVal stTableName As String, _ Optional ByVal blIdentity As Boolean = True, _ Optional ByVal stSearch As String = "") Dim cat As ADOX.Catalog Dim tbl As ADOX.Table Set cat = New ADOX.Catalog Set tbl = New ADOX.Table Dim adoCommand As New ADODB.Command, stCommand As String Dim adoSQLCommand As New ADODB.Command Dim errorString As String
On Error GoTo ErrorCopying PrgPart.Value = PrgPart.Value + 1 If blCancelPressed Then End '???fix later cat.ActiveConnection = db1 'This doesn't seem to work with our normal settings for spectrumDbase tbl.ParentCatalog = cat tbl.Name = "dbo_" & stTableName tbl.Properties("Temporary Table") = False 'possibly, this line will work for Oracle as well tbl.Properties("Jet OLEDB:Link Provider String") = "odbc;DSN= ;DATABASE=database;" tbl.Properties("Jet OLEDB:Remote Table Name") = stTableName tbl.Properties("Jet OLEDB:Create Link") = True tbl.Properties("Jet OLEDB:Table Hidden In Access") = False tbl.Properties("Jet OLEDB:Cache Link Name/Password") = False cat.Tables.Append tbl Suspend 1 adoCommand.CommandType = adCmdText adoCommand.ActiveConnection = database adoSQLCommand.CommandType = adCmdText adoSQLCommand.ActiveConnection = rsDbase
'spectrumDBase.BeginTrans 'stCommand = "BEGIN TRANSACTION " & vbNewLine _ ' & "go" & vbNewLine 'If there is an identity field in the table, it must be temporarily disabled 'to insert from an foreign DB. 'If blIdentity Then ' stCommand = stCommand & "SET IDENTITY_INSERT dbo_" & stTableName & " ON " & vbNewLine & "GO" & vbNewLine 'adoCommand.CommandText = stCommand 'adoCommand.Execute 'End If
'insert the records from the source table stCommand = "" stCommand = stCommand & "INSERT INTO dbo_" & stTableName _ & " SELECT * FROM " & stTableName & vbNewLine _ & "GO" & vbNewLine
Set adoCommand = Nothing Set adoSQLCommand = Nothing Exit Sub ErrorCopying: 'need to save this to a string so it doesn't reset when Resume occurs errorString = Err.Description ' MsgBox "Error copying the [" & stTableName & "] table." & vbNewLine _ ' & "Error: " & errorstring Resume errorCatch errorCatch: On Error Resume Next 'set a log Dim fso As FileSystemObject, fStream As TextStream Set fso = New FileSystemObject Set fStream = fso.OpenTextFile(App.Path & "DBTransfer.log", ForAppending, True) fStream.WriteLine "***Error copying the [" & stTableName & "] table." fStream.WriteLine " Error: " & errorString fStream.WriteLine " " fStream.Close Set fStream = Nothing Set fso = Nothing 'clean up adoCommand.CommandText = "DROP TABLE dbo_" & stTableName adoCommand.Execute If blIdentity Then 'reinsert identity property adoSQLCommand.CommandText = "SET IDENTITY_INSERT " & stTableName & " OFF" adoSQLCommand.Execute End If Set adoCommand = Nothing Set adoSQLCommand = Nothing End Sub
Who convert access dba to ms sql 2000 standard. I try with access conversion, but some buttons commands and rules donīt work. The dba contains tabs, forms, relīs, macros, modules and relations with tabs and examination images. Itīs possible convert everything without damage or transform this itens? The dba contains critical information about identification and personal clinic story about patients, but the access capacity itīs out (2GB) and i need to expand this dba.
I have some urgency to this problem, itīs depends to buy a windows 2008 server and mssql server 2008.
In answering this question you could just tell me what you think would work rather than trying to test it.
The following query works correctly and returns rows with pairs of values repid and repid2. I need loop through a large table and update *its* repid2 with rm_repid2 for any rows where its repid value equals rm_repid but only for the pairs that result in the below query
SELECT rm.repid AS rm_repid ,rm.repid2 AS rm_repid2 ,rm.id2contact ,r.repid AS r_repid ,r.prim AS r_prim FROM sfrep r JOIN sfrepmst rm ON r.repid=rm.repid2 WHERE rm.repid IN ( 'TEST01' ,'TEST02' )
Returns
rm_repid rm_repid2 id2contact r_repid -------- --------- ---------------------------------------- ------- TEST01 NEW01 John Smith NEW01 TEST02 NEW02 Ken Roberts NEW02
I have a table with all varchar data for all different fields for money and int etc. I want to do a calcuation in one field with the rule as below:
UPDATE [dbo].[tblPayments] SET [PreInjuryWage]= CASE WHEN [WeekNo]<14 THEN ([MaxWorkCover]+ [WeeklyEarnings] )/0.95 ELSE ([MaxWorkCover] + 0.80 * [WeeklyEarnings] ) /0.80 END
I tried this command after many other ways of tries
UPDATE [dbo].[tblPayments1] SET [PreInjuryWage]= CASE WHEN [WeekNo]<14 THEN CAST ( (cast([MaxWorkCover] as money )+ cast([WeeklyEarnings] as money ))/0.95 AS Varchar(10) ) ELSE CAST ( (convert(money, [MaxWorkCover] + (0.80 * convert(money, [WeeklyEarnings] )) )/0.80 ) as varchar(10)) END
The structure of the table ( its a legacy table from 2000 i beleive)
CREATE TABLE [dbo].[tblPayments]( [PaymentID] [int] IDENTITY(1,1) NOT NULL, [ClaimID] [int] NOT NULL, [WeekNo] [smallint] NULL,
[code]....
Arithmetic overflow error converting numeric to data type varchar.
Hello does anyone know how to convert this access code to sql. Also is there a program out there that will do it for you.
IIf([Ceridian]![UnionIndicator]="U" And [YearsService]>=3,[HealthBenefits]![medplan.Bi-WeeklyURBio-Rad]*26,[HealthBenefits]![medplan.Bi-WeeklyBio-Rad]*26) AS MedicalCostER, IIf([Ceridian]![UnionIndicator]="U" And [YearsService]>=3,[medplan]![Bi-WeeklyUREE]*26,[medplan]![Bi-WeeklyEE]*26) AS MEdicalCostEE
I am being asked to convert this access query into sql server 2000. Access query SELECT Left(Trim([Notes_Primary_Key]),InStr(Trim([Notes_Primary_Key])," ")) AS PcnPID, Trim([Notes_Secondary_Key]) AS PcnTicketNum FROM tri_offnotes;
I'm new to SQL and am not familiar with which function replaces the InStr access function.
I have an Access database that used to produce a mass of Performance Indicators from Access tables. The data is now held on SQL Server and I run the Access queries from the SQL tables. I wouldlike to move all the queries over to SQL but not sure if I can do that. Here's an example of one of the queries (the SQL view)
SELECT tblCalls.* FROM tblCalls WHERE (((tblCalls.Call_date)>=[Forms]![ReportParams]![SDate] And (tblCalls.Call_date)<=[Forms]![ReportParams]![EDate]) AND ((tblCalls.NotAccepted)=False) AND ((tblCalls.Completed_time) Is Not Null) AND ((tblCalls.Category)="fly tipping"));
SELECT Month([Call_date]) AS Mnth, DateSerial(Year([Call_date]),Int((Month([Call_date])-1)/3)*3+4,0) AS Qtr, Sum(Work_Days([Call_date],[Completed_time])) AS RespTime, Sum(1) AS Count, Sum(Work_Days([Call_date],[Completed_time]))/[Count] AS AvgTime FROM qryFlyTippingStatsSummary1 GROUP BY Month([Call_date]), DateSerial(Year([Call_date]),Int((Month([Call_date])-1)/3)*3+4,0) ORDER BY Month([Call_date]), DateSerial(Year([Call_date]),Int((Month([Call_date])-1)/3)*3+4,0);
I'm going crazy trying to convert an Access Function to SQL.From what I've read, it has to be done as a stored procedure.I'm trying to take a field that is "minutes.seconds" and convert it to minutes.This is what I have in Access:Function ConvertToTime (myAnswer As Variant)Dim myMinutesmyMinutes-(((((myAnswer * 100)Mod 100/100/0.6)+(CInt(myAnswer-0.4))))ConvertToTime =(myMinutes)End FunctionWhen I tried to modify it in SQL:CREATE PROCEDURE [OWNER].[PROCEDURE NAME] AS ConvertToTimeFunction ConvertToTime(myAnswer As Variant)Dim myMinutesmyMinutes = (((((myAnswer * 100)Mod 100)/100/0.6)+9CInt(myAnswer-0.4))))ConvertToTime=(myMinutes)EndI get an error after ConverToTime.
First off, I apologise if this is classed as off topic as it's concerning access but I couldn't see another forum that was better suited for this question.
I'm trying to run this query in Access. I designed it in SQL Management Studio with a test database that I set up and it runs fine. However, when I tried to run it in access I get a syntax error on the subquery bit. Can anyone tell me what I'm doing wrong here?
UPDATE tblInvoice SET tblInvoice.PeriodID = (SELECT p.PeriodID FROM tblPeriod p INNER JOIN tblInvoice i ON i.TransDate BETWEEN p.PeriodStartDate AND p.PeriodEndDate WHERE i.InvoiceID = tblInvoice.InvoiceID)
Hi Guys I need your help again, I am try to update several columns and the data type is 'money'. Below is the code I have used: UPDATE CAT_Products SET UnitCost ='10.00',UnitCost2 = '10.00',UnitCost3 = '10.00',UnitCost4 = '10.00',UnitCost5 = '10.00',UnitCost6 = '10.00' WHERE ProductCode = '0008' But it will not update, instead I get this error: ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- >[Error] Script lines: 1-9 -------------------------- Disallowed implicit conversion from data type varchar to data type money, table 'dbo.CAT_Products', column 'UnitCost'. Use the CONVERT function to run this query. More exceptions ... Disallowed implicit conversion from data type varchar to data type money, table '.dbo.CAT_Products', column 'UnitCost2'. Use the CONVERT function to run this query. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- The error message indicates that I need to use the convert function. But the columns data type is set at 'money' not 'varcher' . So do I need to convert data type to 'varcher' in order to update and convert back to data type 'money' when update complete? Or do I need to indicate in the update statement that data type is already 'money'? I am not sure how I would either. Thanks
I have this update working in an Oracle database and I need to make it run on SQL Server.
UPDATE table3 C SET C.column1 = 'A' WHERE (C.column2, C.column3) IN (SELECT B.column2, B.column3 FROM table1 A, table2 B WHERE A.column2 = B.column2 AND A.column3 = B.column3 AND B.column4 = 1)
I am trying to write an update t-SQL statement from the following select statement:
SELECT EduNextContacts.ssn FROM EduNextContacts Left JOIN EduContactsAuditChanges ON EduNextContacts.ssn = EduContactsAuditChanges.ssn AND EduNextContacts.campaign_code = EduContactsAuditChanges.campaign_code GROUP BY EduNextContacts.ssn HAVING(SUM(CASE EduContactsAuditChanges.release_code WHEN '103' THEN 1 ELSE 0 END) + SUM(CASE EduContactsAuditChanges.release_code WHEN '102' THEN 1 ELSE 0 END) >= 2)
I tried many versions of writing my update statement with no luck. My most recent version is as follows:
UPDATE EduNextContacts
SET EduNextContacts.overLMLimit = 'Y'
FROM EduNextContacts Left JOIN
EduContactsAuditChanges ON EduNextContacts.ssn = EduContactsAuditChanges.ssn AND
HAVING(SUM(CASE EduContactsAuditChanges.release_code WHEN '103' THEN 1 ELSE 0 END) +
SUM(CASE EduContactsAuditChanges.release_code WHEN '102' THEN 1 ELSE 0 END) >= 2))
And gives the following error:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Can anyone help shed some light on how to make an update statement from my SELECT query above?
Sorry if this has been answered before. Could not find any answers. OS Vista Business, SQL Server 2005 Express. I have a CSV file which I imported to Access only 100 records with 8 fields. Then ran Tools >> Database Utilities >> Upsizing Wisard. The result was I exported the table field headers but not the data. Is there any method on how I can get the field headers and data into SQL Server Express?
I send you this message to told hwo can i do to convert one database which is in Access97 to SQL Server6.5. I must create a interface in the web which is able to interrogate the database that the reason why i want to do that. Thanks for any help in advance.
I have an Access application with various DB's linked together. One of the DB's contains a field, SOURCECODE, which was mistakenly entered in as an nvarchar(4000) field in MS Sql Server. When I link the table, Access converts it to a memo field.
There will never be more than 10 chars in that field. The company that created the DB says its will be too risky to change the data type. I need to link this field to another field that's a VARCHAR.
How can I do this? Access doesn't allow the CAST feature.
I have used the Upsizing Wizard in Access 2003 to convert a database to SQL. When I open it using SQL 2000 Desktop edition, I am finding a problem with the views and stored procedures. When I open a query in design view, the tables are displayed in the upper pane without the details of the individual fields. All I get is a tick box next to *(All Columns) If I create a new table, the same thing happens. If I create a new database, then make a table within it, any queries behave normally, with all the fields displayed. I would be grateful for any ideas