|
I need to compare two identically structured tables to get the differences from one of the tables. Any ideas on the easiest/quickest way to do this?
Jason W.
|
|
|
|
|
hello @all,
i have an access data base and a dialogbased program.
to connect the program with the data base i used odbc.
then i add a new class in my project (CRecordset, name: CDatabase) and choose the table i want.
finally i want to register now something into my data base.
I make an object of the data base:
<br />
CDatabase db;<br />
db.Open();<br />
db.Edit();<br />
db.m_x=1;
db.Update();<br />
db.Close();<br />
i get the error in my program, that there is no current data record.
what´s wrong????
Thank you in advance.
|
|
|
|
|
I've tride search after a book about ADO with examples written in C++ but it seems to be impossible!?
Can you help? Is there any ADO books with examples written in C++ and not VBScript/VB?
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
I couldn't find one, but it's not hard to convert. That's WHY they write them in VB, because we C++ programmers can do the conversion and the average VB programmer would not cope converting C++ code to VB.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Christian Graus wrote:
I couldn't find one
Why am I not surprised?
Christian Graus wrote:
but it's not hard to convert. That's WHY they write them in VB, because we C++ programmers can do the conversion and the average VB programmer would not cope converting C++ code to VB.
Is it really that easy?
I feel it's not because _variant_t has no similar type in VB? or?
But if the professional says it's possible.... it shold be possible in some way!
Thanks, then I'll buy ADO 2,6 by Wrox. I think that's the best one I've seen!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
I thought the best one was the one from O Reilly, but I am partial to them. They actually have a chapter showing how stuff works in different languages, then the rest is in VB. Wrox books for me are fat with useless code listings.
Rickard Andersson wrote:
I feel it's not because _variant_t has no similar type in VB? or?
VB has no types, does it ? VBScript doesn't.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Christian Graus wrote:
I thought the best one was the one from O Reilly, but I am partial to them. They actually have a chapter showing how stuff works in different languages,
I will check it out. I Like Wrox books but it's pretty true that you say "useless code listings". But I like when it is a little too mucj code that almost nothing!
Christian Graus wrote:
VB has no types, does it ? VBScript doesn't.
Ooogh... okay... I don't know VB that much... I know VBScript has no types!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
If you use the #import "C:\Program Files\Common Files\System\ADO\msado15.dll" method, then C++ use of ADO is almost as easy as using VB.
The ADO wrapper generated is very nice, with this you shouldn't have any problem converting VB code.
Michael
Fat bottomed girls
You make the rockin' world go round -- Queen
|
|
|
|
|
Hey Mike!
You scared the sh*t out of me!
I thought you had a recomendation of a book about ADO in C++... I've already ordered that book from O´Reilly which Christian suggested me (Which is written in VB)!
Promise me that you'll never do that again!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
|
How to rollback triggers inside stored procedure...
Thanks ...
|
|
|
|
|
From SQL books Online:
Rollbacks in Stored Procedures and Triggers
If @@TRANCOUNT has a different value when a stored procedure finishes than it had when the procedure was executed, an informational error 266 is generated. This error is not generated by the same condition in triggers.
A 266 error is generated when a stored procedure is called with an @@TRANCOUNT of 1 or greater and the procedure executes a ROLLBACK TRANSACTION or ROLLBACK WORK statement. This is because ROLLBACK rolls back all outstanding transactions and decrements @@TRANCOUNT to 0, which is a lower value than it had when the procedure was called.
If a ROLLBACK TRANSACTION is issued in a trigger:
All data modifications made to that point in the current transaction are rolled back, including any that were made by the trigger.
The trigger continues executing any remaining statements after the ROLLBACK statement. If any of these statements modify data, the modifications are not rolled back. No nested triggers are fired by the execution of these remaining statements.
None of the statements in the batch after the statement that fired the trigger are executed.
A ROLLBACK in a trigger closes and deallocates all cursors that were declared and opened in the batch containing the statement that fired the trigger. This includes cursors declared and opened in stored procedures called by the batch that fired the trigger. Cursors declared in a batch prior to the batch that fired the trigger are only closed, except that STATIC or INSENSITIVE cursors are left open if:
CURSOR_CLOSE_ON_COMMIT is set OFF.
The static cursor is either synchronous, or a fully populated asynchronous cursor.
A trigger always operates as if there were an outstanding transaction in effect when the trigger is executed. This is definitely true if the statement firing the trigger is in an implicit or explicit transaction. It is also true in autocommit mode. When a statement begins executing in autocommit mode, there is an implied BEGIN TRANSACTION to allow the recovery of all modifications generated by the statement if it encounters an error. This implied transaction has no effect on the other statements in the batch because it is either committed or rolled back when the statement completes. This implied transaction is still in effect, however, when a trigger is called.
This means that any time a BEGIN TRANSACTION statement is issued in the trigger, it is actually beginning a nested transaction. Because a nested BEGIN TRANSACTION statement is ignored when rolling back nested transactions, ROLLBACK TRANSACTION issued in the trigger always rolls back past any BEGIN TRANSACTION statements issued by the trigger itself. ROLLBACK rolls back to the outermost BEGIN TRANSACTION.
You must use the SAVE TRANSACTION statement to do a partial rollback in a trigger, even if it is always called in autocommit mode. This is illustrated by the following trigger:
CREATE TRIGGER TestTrig ON TestTab FOR UPDATE AS
SAVE TRANSACTION MyName
INSERT INTO TestAudit
SELECT * FROM inserted
IF (@@error <> 0)
BEGIN
ROLLBACK TRANSACTION MyName
END
This also affects COMMIT TRANSACTION statements that follow a BEGIN TRANSACTION statement in a trigger. Because BEGIN TRANSACTION starts a nested transaction, a subsequent COMMIT statement applies only to the nested transaction. If a ROLLBACK TRANSACTION statement is executed after COMMIT, ROLLBACK rolls back everything to the outermost BEGIN TRANSACTION. This is illustrated by the following trigger:
CREATE TRIGGER TestTrig ON TestTab FOR UPDATE AS
BEGIN TRANSACTION
INSERT INTO TrigTarget
SELECT * FROM inserted
COMMIT TRANSACTION
ROLLBACK TRANSACTION
This trigger will never insert into the TrigTarget table. BEGIN TRANSACTION always starts a nested transaction. COMMIT TRANSACTION commits only the nested transaction, while the following ROLLBACK TRANSACTION rolls everything back to the outermost BEGIN TRANSACTION.
BTW the SQL Books Online can be downloaded from microsoft[^]
I may be somewhat used, but I'm not used up!
R
|
|
|
|
|
Can I distribute MSDE and MDAC?
I have a client, a non-profit with a non-budget, that needs to track data on persons they've provided assistance to, but I'd rather not have them buy Access if there's no need for it. The need is simple - recipient name, ID, date, nature of service provided, etc. One table will probably do it, and since they're running XP Pro, I can probably set it up as a browser-based app using IIS. Only one of the staff will ever need to access it, so the two connection limit is no burden.
Is it okay to just create the db in SQL Server at home, export the db to their system, and install MSDE and MDAC on their machines? For that matter, I think MDAC is part of XP, so it really only needs MSDE.
"My child was Inmate of the Month at Mohave County Jail" - Bumper Sticker in Bullhead City, AZ
|
|
|
|
|
Check this[^] out.
Also, if it is for a non-profit, maybe contact your local MS office and see if they'll sponsor you some software.
Cheers,
Simon
"From now on, if rogue states want to buy weapons of mass destruction, they're going to have to go on eBay," Mr. Bezos said.
|
|
|
|
|
Thank you for the link, Simon! It appears that I'm legal. I got my copy as a user of VS6 Professional, so I'm legal to distribute MSDE with single-purpose applications. Something this simple will never be deemed a competitive product, and if I can't use it with IIS, I can always make do with VB. It's hardly worth the effort to fire up VC++ for anything this trivial.
"My child was Inmate of the Month at Mohave County Jail" - Bumper Sticker in Bullhead City, AZ
|
|
|
|
|
now i want to repair and compact the access2000 database in my app
and use ado to do these,who can tell me how to do?
thanks!
-----------------------------
Mr.Whelk
-----------------------------
Zhuhai City ,Guangdong ,China
|
|
|
|
|
if you can understand this, it was copied from MSDN.
Visual C++: Compacting an Access Database via ADO
Besides #import, the Msado15.dll (MDAC2.1), add the following #import statement to generate the wrapper classes for JRO to your .cpp classes (alternatively, you can generate the wrapper classes more efficiently by using the no_implementation and implementation_only attributes of the #import pre-processor statement):
#import "C:\PROGRAM FILES\COMMON FILES\System\ado\MSJRO.DLL" no_namespace
Add the following (specifying your own source and destination database paths) to the .cpp file where you want to compact the database:
...
try
{
IJetEnginePtr jet(__uuidof(JetEngine));
jet->CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\nwind2.mdb", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\abbc.mdb;Jet OLEDB:Engine Type=4");
}
catch(_com_error &e)
{
::MessageBox(NULL, (LPCTSTR)e.Description( ), "", MB_OK) ;
}
Good Luck!
JW
|
|
|
|
|
thanks,i will try it!!
-----------------------------
Mr.Whelk
-----------------------------
Zhuhai City ,Guangdong ,China
|
|
|
|
|
hey,a question is:
if the access2000 database have a password, i want to the compacted database
have the same password ,i try following:
IJetEnginePtr jet(__uuidof(JetEngine));<br />
jet->CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\study\\bardemo\\Debug\\personal.mdb;Persist Security Info=False;Jet OLEDB:Database Password=simcos",<br />
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\study\\bardemo\\Debug\\personalbackup.mdb");
but after compacted the backup database lost its password.
how can i save the password?
help me ,thanks!
-----------------------------
Mr.Whelk
-----------------------------
Zhuhai City ,Guangdong ,China
|
|
|
|
|
try include the following property in your dest provider
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\study\\bardemo\\Debug\\personalbackup.mdb;Jet OLEDB:New Database Password=123456");
Good luck!
JW
|
|
|
|
|
it is ok.thanks very much!hope to make friend with you!
my email is :ehq@eastcompeace.com
thanks!
-----------------------------
Mr.Whelk
-----------------------------
Zhuhai City ,Guangdong ,China
|
|
|
|
|
You are welcomed, please check the dest file by Access 2000. Make sure the new password is function.
JW
|
|
|
|
|
It already has that resolution (actually 100 nanosecond resolution), but if you are displaying it in a datagrid the default column format does not show it. try:
private static String timeFormat = "MM/dd/yy HH:mm:ss:fff";<br />
private static int timeColumnWidth = 120;<br />
<br />
DataGridTableStyle ts1 = new DataGridTableStyle();<br />
foreach (DataColumn dc in dataTable.Columns)<br />
if (dc.DataType == typeof(DateTime))<br />
{<br />
columnFmt.Format = timeFormat;<br />
columnFmt.Width = timeColumnWidth;<br />
}<br />
ts1.GridColumnStyles.Add(columnFmt);<br />
ts1.MappingName = dataTable.TableName;<br />
ts1.ColumnHeadersVisible = true;<br />
ts1.ReadOnly = true;<br />
dataGrid1.TableStyles.Clear();<br />
dataGrid1.TableStyles.Add(ts1);<br />
dataGrid1.DataSource = dataTable;<br />
<br />
If you are trying to save this to SQL server, it can only handle a resolution of 3 ms in the SqlDateTime fields, Other databases may share the same lack of resolution or worse with thier 'Native' date/time columns You might have to convert the DateTimes to a long integer (DateTime.Ticks) and save that, converting back when you read it
-- Always be sure to maintain adequate insulation between lap and Laptop
Rob
|
|
|
|
|
Thanks a lot for your guidance.
and how can I fill a datetime field in a table programmatically with millisecond resolution for example in C# syntax?
Thank you in dvance.
|
|
|
|
|
Hi,All
RecordCount Property giving me -1 value
Please read my code and give me where i am doing wrong;
and also please comment on my Code(if their any mistakes)
Thanks in Advance..
/////////////This is my code To Test the Function////////////////////
_RecordsetPtr pRst;
CString strTemp;
pRst.CreateInstance(__uuidof(Recordset));
pRst=GetData(1);
if(pRst!=NULL)
{
int nCount=(int)pRst->RecordCount;
strTemp.Format("%d",nCount);
AfxMessageBox(strTemp);
}
else
{
AfxMessageBox("Recordset null");
}
pRst.Close();
pRst.Release();
////////////////////////////////////
///////////////////This is my funtion which will return me Recordset object///////////
_RecordsetPtr GetData(int nType)
{
CString strType;
strType.Format("%d",nType);
try
{
//COM Library Initialization
if(FAILED(::CoInitialize(NULL)))
{
//Log error
return NULL;
}//if(FAILED(::CoInitialize(NULL))
//Open the Connection
m_hr=m_pConnection.CreateInstance(__uuidof(Connection));
if(FAILED(m_hr))
{
::CoUninitialize();
//Log error
return NULL;
}
m_strCnnString=GetConnectionString();//It will give me the Connection String
_bstr_t cnnString(m_strCnnString);
_bstr_t bstrEmpty("");
m_hr=m_pConnection->Open(cnnString,bstrEmpty,bstrEmpty,adConnectUnspecified);
if(FAILED(m_hr))
{
m_pConnection.Release();
::CoUninitialize();
//Log error
return NULL;
}
//Get the Command objet
m_hr=m_pCommand.CreateInstance(__uuidof(Command));
if(FAILED(m_hr))
{
m_pConnection->Close();
m_pConnection.Release();
::CoUninitialize();
//Log error
return NULL;
}
m_pCommand->ActiveConnection=m_pConnection;
m_pCommand->CommandText="Sp_GetData";
m_pCommand->CommandType=adCmdStoredProc;
//Append the Parameters to Command object
//Type Parameter
m_pParam=m_pCommand->CreateParameter(_bstr_t("Type"),adInteger,adParamInput,4,_variant_t(strType));
m_pCommand->Parameters->Append(m_pParam);
m_hr=m_pRecordSet.CreateInstance(__uuidof(Recordset));
if(FAILED(m_hr))
{
m_pConnection->Close();
m_pConnection.Release();
::CoUninitialize();
//Log error
return NULL;
}
//Execute the SP
m_pRecordSet->CursorType=adOpenStatic;
m_pRecordSet=m_pCommand->Execute(NULL,NULL,adCmdStoredProc);
return m_pRecordSet;
}//try block
catch(_com_error &comExcep)
{
//Handle the error
}
catch(CException * GenExcep)
{
//Handle the error
GenExcep->Delete();
}
//CleanUp the objects
if(m_pCommand!=NULL)
{
m_pCommand.Release();
}
if(m_pConnection!=NULL)
{
m_pConnection->Close();
m_pConnection.Release();
}
::CoUninitialize();
return NULL;
}
//////////////////This is my StoredProcedure /////////
CREATE PROCEDURE [dbo].[Sp_GetData]
(
@Type[int]
)
AS
Begin
SELECT
Data1,
Data2,
Data3
Data4,
Data5
FROM
tblTestData
WHERE
(Data1=@Type)
End
GO
/////////////////////////////////////////////
anju
|
|
|
|
|