i have a vb6 application that i am using DAO to create a connection to a database and trying to open a recordset. the database is a foxpro database and i have refernece to Microsoft DAO 2.5/3.5 Compatibility Library.
my code is as follows
Dim gdbSMS As Database
If gdbSMS Is Nothing Then
Set gdbSMS = OpenDatabase("C:\Work\M2M Test\DATA", False, False, "Foxpro 2.6;")
End If
Dim sql As String
sql = "select *, substr(lineitem,8,6) as aa from shippers where shipper = '001322' order by aa"
Dim rsShipper As DAO.Recordset
Set rsShipper = gdbSMS.OpenRecordset(sql)
Do While Not rsShipper.EOF
Beep
rsShipper.MoveNext
Loop
rsShipper.Close
when i execute teh line for openrecordset i get an error "undefinied function 'substr' in expression
i run the exact same query in foxpro and it works fine. any thoughts on what i need to do to get this to work with substring functions?
thanks
Try using the T-SQL SUBSTRING function instead.
SUBSTRING ( value_expression , start_expression , length_expression )
Without using DAO recordsets, but instead using DataTables, and data adapters using OleDBProvider for Foxpro data (definitely not going back to Fox 2.x) gives you more current flexibility in querying....
That said, you could try by doing what SUBSTR() actually does... Try changing to
RIGHT( LEFT( LineItem, 14 ), 6 ) as AA
Related
How to load all fields name into combo box. I am using visual basic 6.0.
My code is like this.
Private Sub combo2_option()
Call Dbase
Set rs = New ADODB.Recordset
rs.Open "select ID,DATE,REFNO,SUPPLIER,MODEL,SERIAL,DESCRIPTION,UOM,CATEGORY,PUH,GDP from product_aging_monitoring ", db, 3, 3
Combo2.AddItem rs(2)
End Sub
Option 1. You can limit the records to 1 if you wish to get only the field names.
For i=0 to rs.fields.count-1
Combo2.AddItem rs.fields(i).Name
Next
Option 2 is to use ADOX (DAO) Reference instead of writing a select query. Use ADOX.Catelog object to get metadata of the tables and database
I have no problem when trying to execute and insert or a delete SQL Command. However, this update command does not seems to work well and I am having a hard time to figure it out. Kindly help me please.
I am using an i Series or AS/400 database.
Imports IBM.Data.DB2
Imports IBM.Data.DB2.iSeries
Public conn As New iDB2Connection
Public str As String = "Datasource=10.0.1.11;UserID=edith;password=edith;DefaultCollection=impexplib"
Dim cmdUpdate As New iDB2Command
Dim sqlUpdate As String
conn = New iDB2Connection(str)
conn.Open()
sqlUpdate = "UPDATE impexplib.expusers SET loginDate=#loginDate, loginTime=#loginTime WHERE username=#username"
cmdUpdate.Parameters.Add("username", iDB2DbType.iDB2VarChar)
cmdUpdate.Parameters.Add("loginDate", iDB2DbType.iDB2Date)
cmdUpdate.Parameters.Add("loginTime", iDB2DbType.iDB2Time)
cmdUpdate.Parameters("username").Value = txtUsername.Text
cmdUpdate.Parameters("loginDate").Value = Now.ToString("d")
cmdUpdate.Parameters("loginTime").Value = Now.ToString("T")
cmdUpdate.Connection = conn
cmdUpdate.CommandText = sqlUpdate
cmdUpdate.ExecuteNonQuery()
conn.Close()
Please help me what I am doing wrong? The update code does not really work. Even a simple update of password does not work to.
Thanks!
Assuming no error messages anywhere, if no update is occurring, then the WHERE clause is not being satisfied. Make sure that the user name in DB2 exactly matches the parameter used in the WHERE clause. Very often, DB2 columns are CHAR, not VARCHAR or the other way round. You may also have a situation where the DB2 column is all upper case and the parameter is mixed case. Imagine the DB2 column has "FRED BLOGGS " and your parameter has "Fred Bloggs". This won't satisfy the WHERE clause and no rows will be updated.
i have an VBA code where i am calling oracle to retrieve data twice using ODBC.
First data retrieval is fine. But 2nd time it is saying ,
**RunTime Error '-2147467259 (80004005)'; Unspecified error**
My Code is as follows,
Note: Same code works for connecting Teradata but failed when i use
Oracle
'First Data retrieval
Query1 = "Select TableName from all_tables"
CmdSQLData.CommandText = Query1
CmdSQLData.CommandType = adcmdText
CmdSQLData.Timeout=0
set rs = CmdSQLData.Execute()
'Then code to store data ...
'This part gives proper result ...
rs.close()
'Second Data retrieval
Query2 = "Select * from db.Event"
CmdSQLData.CommandText = Query2
CmdSQLData.CommandType = adcmdText
CmdSQLData.Timeout=0
set rs = CmdSQLData.Execute() 'This line Gives Error - RunTime Error '-2147467259 (80004005)'; Unspecified error
Also i tried creating new command object as cmdSQLData1 but still same
error
May i know why the error is coming for second query ?
There is no problem with query as i have tested in oracle directory.
Please let me know
You won't see this documented much of anywhere, but reusing Command objects with different comamndText is actually a bad practice. You don't say what kind of connection you're using, but for example if it's ODBC, this will internally send a fake invalid SQL to Oracle to force a cleanup of some kind. So instead, throw away your Command object after use and create a new one.
Reusing Command objects is a good practice when you're re-executing the same query with different parameter values, but that's not the case here.
You do not need to use command text at all for those types of queries what you could do is :-
` Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
con.Open "DSN=Oracle", "User", "Password"
rs.Open "select * from table_a", con
' Read all results
rs.Close
rs.Open "select * from table_b", con
' Read all results
rs.Close
con.Close
You only need to use "Command" if you plan to use a store procedure or a query with bound parameters.
I'm working to retrieve data from oracle 9i to lotus notes. I'm using Oracle 10g for testing since that's what I had. In the default HR database, there is an EMPLOYEES table. I've recently added a new column to get the last modified timestamp which is successful. The data is in the form like this: 25-JUL-12 10.28.32.000000 AM
The following is my lotusscript code:
Option Public
Option Declare
UseLSX "*lsxlc"
%Include "lsconst.lss"
Sub Initialize
Dim s As New NotesSession, db As NotesDatabase
Set db=s.Currentdatabase
Dim lcs As New Lcsession
lcs.Clearstatus
Dim conUser As New Lcconnection("Oracle")
Dim staffdoc As NotesDocument
Dim fieldlistuser$
fieldlistuser="EMPLOYEE_ID,FIRST_NAME,MODIFIED_AT"
conUser.Server="localhost"
conUser.UserID="hr"
conUser.Password="hr"
conUser.Connect
conUser.MetaData="HR.EMPLOYEES"
conUser.Fieldnames=fieldlistuser
Dim fieldsUser As New LCFieldList
Dim fieldUser As LCField
Call conUser.Execute("Select * From HR.EMPLOYEES", fieldsUser)
While conUser.Fetch(fieldsUser) > 0
Set staffdoc=New NotesDocument(db)
staffdoc.Form="Staff"
staffdoc.StaffID=fieldsUser.EMPLOYEE_ID(0)
staffdoc.StaffName=fieldsUser.FIRST_NAME(0)
staffdoc.DateJoin=fieldsUser.MODIFIED_AT(0)
Call staffdoc.Save(True, True)
Wend
conUser.Disconnect
End Sub
Previously everything was ok before I added the timestamp column in the EMPLOYEES table and I can export every row to a temporary lotus view. Now the error always stop at Call conUser.Execute("Select * From HR.EMPLOYEES", fieldsUser). I thought it has something to do with the line fieldlistuser="EMPLOYEE_ID,FIRST_NAME,MODIFIED_AT" so I remove MODIFIED_AT from it and commented staffdoc.DateJoin=fieldsUser.MODIFIED_AT(0) but the error still occurs. The error is Error: Invalid data type for field 'MODIFIED_AT', Connector'Oracle', Method -Execute-. Can this actually be done at all? If can, what datatype in lotus should I store the timestamp value?
My first thought is does the select statement work fine at the server?
Assuming it does, this looks like a problem with the driver converting the timestamp to a Lotus Notes datetime field. As a workaround you could create a stored procedure that returns 'modified at' as a datetime instead of a timestamp type.
Just looking at help docs and I'm wondering if captialization matters, as the LCConnection property I see listed is FieldNames, not Fieldnames.
I'm trying to execute a SQL query through ODP.NET to create a table, but I always get an ORA-00911 'invalid character' error. The Errors object in the exception always has the text "ORA-00911: invalid character\n", even if there are no linebreaks in the SQL query itself.
The code I'm executing the SQL is this:
using (OracleConnection conn = new OracleConnection(<connection string>) {
using (OracleCommand command = conn.CreateCommand()) {
conn.Open();
command.CommandText = queryString;
command.ExecuteNonQuery(); // exception always gets thrown here
}
queryString contains a single CREATE TABLE statement, which works fine when executed through SQL Developer
EDIT: the SQL I am executing is this:
CREATE TABLE "TESTSYNC"."NEWTABLE" (
"COL1" NUMBER(*,0) NULL,
"COL2" NUMBER(*,0) NULL
);
with linebreaks removed
Other people have come across this issue - ODP.NET does not support multiple SQL statements in a text command. The solution is to wrap it in a PL/SQL block with EXECUTE IMMEDIATE around each statement. This lack of support for ; seems incredibly boneheaded to me, and has not improved my opinion of the oracle development team.
Furthermore, this seems to be an issue with oracle itself, as I have the same problems with the MS and ODBC oracle clients.
I had this issue for some reason you have to have code on one line.
I had strSQL = "stuff" +
" more stuff"
I had to put it on one line.
strSQL = "stuff more stuff"
It some how reads the cr/lf.
Wrap your sql in a Begin block.
Dim sqlInsert As String = ""
For i = 1 To 10
sqlInsert += "INSERT INTO MY_TABLE (COUNT) VALUES (" & i & "); "
Next
Call ExecuteSql("BEGIN " & sqlInsert & " END;")
Your quotes are OK (it just forces Oracle to treat your object names as case sensitive i.e. upper case the way you've written it) but I'm not at all sure you're allowed to define NUMBER that way with a *.
I wonder if it is the "*" in the sql have you tried the call without an * in the create? I bet it is yet another "feature" of the ODP.Net driver