How to get the auto-increment column from a table of MS Access Database using ADO and C++? - ado

I have used the following way to determine if a column is auto-increment:
att = Rs1->Fields->GetItem((long)nIndex)->Attributes;
bAutoIncrement = att & adFldRowID;
But it doesn't work at all.
Do anyone have good ideas about this? Thanks in advance.

Dim ADOXCatalog As New ADOX.Catalog
Dim ADOConnection As New ADODB.Connection
Try
ADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\db1.mdb;" & _
"Jet OLEDB:Engine Type=4;")
ADOXCatalog.ActiveConnection = ADOConnection
Dim col As ADOX.Column
For Each col In ADOXCatalog.Tables("Table1").Columns
If col.Properties("AutoIncrement").Value = True Then
Console.WriteLine(col.Name)
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
ADOConnection.Close()
End Try

Use This:
try{
ADOX::_CatalogPtr pCatalog= NULL;
pCatalog.CreateInstance(__uuidof(ADOX::Catalog));
pCatalog->PutActiveConnection( _variant_t( (IDispatch*)m_ipConnection ) );
bool v = pCatalog->Tables->GetItem(bstrTableName)->Columns->GetItem(L"PlaceholderForAutoIncrementFieldName")->Properties->GetItem("AutoIncrement")->Value;
return v;
}
catch(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
TRACE("\n\tSource : %s \n\tdescription : %s \n ", (LPCSTR)bstrSource, (LPCSTR) bstrDescription);
}

ADOX::PropertyPtr pAutoIncrProperty = m_pTable->Columns->Item[_variant_t(fieldInfo.m_strName)]->Properties->Item[_variant_t(_T("AutoIncrement"))];

Related

Parameters do not pass to a MySql stored procedure from F#

I'd like to invoke a stored procedure with parameters from F#, but it results in exception "MySql.Data.MySqlClient.MySqlException (0x80004005): Incorrect number of arguments for PROCEDURE test.GetValue; expected 1, got 0".
A similar code in C# works perfectly.
This is .NetCoreApp3.1, FSharp.Core/4.7.0 and MySql.Data/8.0.20. MySql server is 8.0.20, OS is Ubuntu 18.04.4 LTS.
Question: Am I doing sth. wrong or is it a bug?
NOTE: If I remove the parameter from stored procedure and hard-code it in its SELECT query, it works fine in F#. Also, when debugging, I can see the parameters perfectly in place before the call.
F# code that results in exception:
module test_mysql_fsharp.main
open System
open System.Data
open MySql.Data.MySqlClient
[<EntryPoint>]
let main argv =
Console.WriteLine("Hello from test_mysql_fsharp !");
let execStoredProc cs storedProcedureName storedProcedureParameters =
use mySqlConnection = new MySqlConnection(cs)
use command = new MySqlCommand(storedProcedureName, mySqlConnection)
command.CommandType = CommandType.StoredProcedure |> ignore
storedProcedureParameters |> List.iter(fun par -> command.Parameters.AddWithValue(par) |> ignore)
mySqlConnection.Open()
let dataTable = new DataTable()
dataTable.Load(command.ExecuteReader())
dataTable
let cs = "server=127.0.0.1;port=3306;database=test;Uid=***;Pwd=***;"
execStoredProc cs "GetValue" [("par0","KA")] |> ignore
0
The similar code in C# works perfectly:
using System;
using System.Collections.Generic;
using System.Data;
using MySql.Data.MySqlClient;
namespace test_mysql_csharp
{
static class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello from test_mysql_csharp !");
var cs = "server=127.0.0.1;port=3306;database=test;Uid=***;Pwd=***;";
var sp = "GetValue";
var ps = new List<MySqlParameter>();
var p = new MySqlParameter("par0", "KA");
ps.Add(p);
var b = ExecStoredProc(cs, sp, ps.ToArray());
}
private static System.Data.DataTable ExecStoredProc(string cs, string spName,
params MySqlParameter[] spParams)
{
using MySqlConnection connection = new MySqlConnection(cs);
using MySqlCommand command = new MySqlCommand(spName, connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddRange(spParams);
connection.Open();
DataTable dt = new DataTable();
dt.Load(command.ExecuteReader());
return dt;
}
}
}
A few lines to recreate test database and table:
CREATE SCHEMA `test` DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci ;
use test;
CREATE TABLE `test`.`test` (
`k` VARCHAR(64) NOT NULL,
`v` VARCHAR(64) NULL,
PRIMARY KEY (`k`));
INSERT INTO test.test (k,v) values ('KA','VA');
DELIMITER $$
CREATE PROCEDURE `GetValue`(par0 varchar(64))
BEGIN
select * from test.test where k = par0;
END$$
DELIMITER ;
Thank you in advance -
Simple: What does THIS do?
command.CommandType = CommandType.StoredProcedure |> ignore
It just compared 2 values.
Should be:
command.CommandType <- CommandType.StoredProcedure |> ignore

Log Parser 2.2 Registry Wildcard Search

I'm trying to figure out if there is a way to do a wildcard registry search using Log Parser 2.2. A sample of what I'm trying to do:
try
{
LogQuery qry = new LogQuery();
RegistryInputFormat registryFormat = new RegistryInputFormat();
string query = #"SELECT Path FROM \HKCU\Software WHERE Value='%keyword%'";
rs = qry.Execute(query, registryFormat);
for (; !rs.atEnd(); rs.moveNext())
listBox1.Items.Add(rs.getRecord().toNativeString(","));
}
finally
{
rs.close();
}
WHERE Value='%keyword%' does not seem to work and is specific to what is entered in within the '' and specifically searches %keyword% versus the percent signs being wildcards.
Okay nevermind, got it figured out:
RegRecordSet rs = null;
try
{
LogQuery qry = new LogQuery();
RegistryInputFormat registryFormat = new RegistryInputFormat();
string query = #"SELECT Path FROM \HKCU\Software WHERE Value LIKE '%keyword%'";
rs = qry.Execute(query, registryFormat);
for (; !rs.atEnd(); rs.moveNext())
listBox1.Items.Add(rs.getRecord().toNativeString(","));
}
finally
{
rs.close();
}

LSXLC ODBC Stored Procedure

I'm trying to connect to an Oracle RDB database using LSXLC (ODBC Connector).
But when it comes to stored procedures I'm having a hard time getting it to work.
The code below always results in "Error: Parameter name not supplied: fnl_date, Connector 'odbc2', Method -Call-". The error is triggered on "count = connection.Call(input, 1, result)"
Can anyone tell me what I'm doing wrong?
Public Function testLsxlcProc()
On Error GoTo handleError
Dim connection As LCConnection("odbc2")
connection.Server = "source"
connection.Userid = "userid"
connection.Password = "password"
connection.procedure = "proc_name"
connection.Connect
If connection.IsConnected Then
Dim input As New LCFieldList()
Dim result As New LCFieldList()
Dim break As LCField
Set break = input.Append("fnl_date", LCTYPE_TEXT)
break.Text = "2014-07-01"
Dim agrNo As LCField
Set agrNo = input.Append("fnl_agreement_no", LCTYPE_TEXT)
agrNo.Text = "123456"
Dim curr As LCField
Set curr = input.Append("fnl_currency_code", LCTYPE_TEXT)
curr.Text = "SEK"
Dim stock As LCField
Set stock = input.Append("fnl_stock_id", LCTYPE_TEXT)
stock.Text = "01"
connection.Fieldnames = "status, value"
Dim count As Integer
count = connection.Call(input, 1, result)
Call logger.debug("Count: " & count)
Else
Error 2000, "Unable to connect to database."
End If
handleExit:
connection.Disconnect
Exit Function
handleError:
On Error Resume Next
Call logger.error(Nothing)
Resume handleExit
End Function
Thanks in advance!
I had made a stupid mistake and had a mismatch between the name of the input parameter in Domino and the name of the input parameter in the stored procedure.
Make sure all names match up and there shouldn't be a problem.
Stored-Procedure "mylib.MyStoredProc" wird aufgerufen ...
LcSession.Status = 12325: LC-Error: errCallStoredProc 12325 (Error: Parameter name not supplied: P_S651_AC, Connector 'odbc2', Method -Call-)
Solution: changed "mylib" into "MYLIB" and all was well.
Check not only Parameter-Names, but also the Search-Path.

How to convert integer to text for usage in textfield java-blackberry

I want to use an integer value in a TextField. In the below code I am retrieving integer value from table into textfield3. When I use getInteger(2) it is giving error. So what would be the alternative. If parsing is the solution (e.g. .toString) how is it to be implemented in this approach?
TextField3 = new TextField("Amount: ",r.getString(2));
add(TextField3);
This is what I am exactly trying to do
try
{
//Open or create the database
Database db = DatabaseFactory.openOrCreate("database1.db");
//Retrieval
Statement statement1 = db.createStatement("SELECT date,name,amount,narration FROM Bills where id='"+TextField00.getText()+"'");
//This is one text field to accept id value
statement1.prepare();
statement1.execute();
Cursor c = statement1.getCursor();
Row r;
while(c.next())
{
r = c.getRow();
TextField5 = new TextField("Date: ",r.getString(0));
add(TextField5);
TextField2 = new TextField("Customer Name: ",r.getString(1));
add(TextField2);
TextField3 = new TextField("Amount: ",r.getString(2));
add(TextField3);
TextField4 = new TextField("Narration: ",r.getString(3));
add(TextField4);
}
//statement1.prepare();
//statement1.execute();
statement1.close();
db.close();
}
catch( Exception e )
{
System.out.println( e.getMessage() );
e.printStackTrace();
}
Hope it aids your understanding.
Try this line,
TextField3 = new TextField("Amount: ", r.getInteger(2) + "");
Instead of
TextField3 = new TextField("Amount: ",r.getString(2));
You can use java.lang.Integer.toString():
TextField3 = new TextField("Amount: ", Integer.toString(r.getInteger(2)));

Why does my stored procedure always think there is a value?

I have an ASP.NET 2010 app hitting a SQL 2005 db. I am attempting to build a stored proc dynamically, depending on the values selected on a search screen. I have done this many times in previosu versions of .net & sql with no problem. However, now, my IF statement always always acts as though no data was passed in. I have debugged the app and am sure that data is being set. I should note that when I run the procedure directly, with or without data, the correct data is returned.
Here is the rather simple stored proc..
ALTER PROCEDURE get_cases_by_search_criteria
#vin as varchar(30) = null
AS
declare #sqlstr varchar(1000)
set #sqlstr = 'SELECT
[Case].CaseID,
[Case].VIN,
[Case].Make,
[Case].Model,
[Case].VehicleYear,
if #vin is not null and #vin <> ''
set #sqlstr = #sqlstr + ' and ' + ('[Case].VIN = ''' + convert(varchar,#vin) + '''')
exec(#sqlstr)
RETURN
And here is the code that calls the stored proc...
Public Function GetCases(ByVal oSearchCriteria As SearchCriteria) As List(Of BE.Case)
Dim lstCase As New List(Of BE.Case)
Dim oCase As BE.Case
Dim oProviderFactory As New ProviderFactory
Dim oConnection As DbConnection
Dim oReader As System.Data.IDataReader
Dim oFactory As DbProviderFactory
Dim oCmd As DbCommand
Dim param1 As System.Data.Common.DbParameter
Try
'call my class to get an instance of the DBProviderFactory class
oFactory = oProviderFactory.GetFactory
'call another class of mine. pass in the DBProviderFactory class which will create a non-provider-specific connection object
oConnection = oProviderFactory.GetProviderConnection(oFactory)
'non-specific create command
oCmd = oConnection.CreateCommand
'non-specific parameter
If oSearchCriteria.VIN.Length = 0 Then
param1 = oFactory.CreateParameter()
param1.ParameterName = "#vin"
param1.DbType = DbType.String
param1.Value = DBNull.Value
oCmd.Parameters.Add(param1)
Else
param1 = oFactory.CreateParameter()
param1.ParameterName = "#vin"
param1.DbType = DbType.String
param1.Value = oSearchCriteria.VIN
oCmd.Parameters.Add(param1)
End If
oCmd.CommandType = CommandType.StoredProcedure
oCmd.CommandText = "get_cases_by_search_criteria"
Using (oConnection)
oConnection.Open()
oReader = oCmd.ExecuteReader()
While oReader.Read
oCase = New BE.Case
'Case
If oReader("CaseID") IsNot System.DBNull.Value Then oCase.CaseID = oReader("CaseID")
If oReader("Make") IsNot System.DBNull.Value Then oCase.Make = oReader("Make")
If oReader("Model") IsNot System.DBNull.Value Then oCase.Model = oReader("Model")
If oReader("VehicleYear") IsNot System.DBNull.Value Then oCase.VehicleYear = oReader("VehicleYear")
If oReader("VIN") IsNot System.DBNull.Value Then oCase.VIN = oReader("VIN")
lstCase.Add(oCase)
End While
oConnection.Close()
End Using
Catch ex As Exception
Throw ex
End Try
Return lstCase
End Function

Resources