|
Hi, I have a problem that need someone conver give me the sample that conver from my below code. In VB6 I'm very easy to connect to Ms access database. Here is my code.
Dim dbs As DAO.Database<br />
Dim rst As DAO.Recordset<br />
<br />
Private Sub Form_Load()<br />
<br />
' Connect to database.<br />
Set dbs = DBEngine.OpenDatabase("DbPath")<br />
Set rst = dbs.OpenRecordset("SELECT * FROM [TableName]")<br />
<br />
' Check if there is a record in database.<br />
If rst.RecordCount > 0 Then<br />
' Populate the recordset.<br />
rst.MoveFirst<br />
rst.MoveLast<br />
<br />
' Pass the value of the record to the textbox.<br />
Text1.Text = rst.Fields(0).Value<br />
Text2.Text = rst.Fields(1).Value<br />
End If<br />
<br />
End Sub<br />
<br />
Private Sub cmdAdd_Click()<br />
<br />
With rst<br />
.AddNew<br />
.Fields(0).Value = Text1.Text<br />
.Fields(1).Value = Text2.Text<br />
.Update<br />
End With<br />
<br />
End Sub<br />
<br />
Private Sub cmdUpdate_Click()<br />
<br />
With rst<br />
.Edit<br />
.Fields(0).Value = Text1.Text<br />
.Fields(1).Value = Text2.Text<br />
.Update<br />
End With<br />
<br />
End Sub<br />
<br />
Private Sub cmdDelete_Click()<br />
<br />
rst.Delete<br />
<br />
End Sub<br />
<br />
Private Sub cmdFirst_Click()<br />
<br />
rst.MoveFirst<br />
Text1.Text = rst.Fields(0).Value<br />
Text2.Text = rst.Fields(1).Value<br />
<br />
End Sub<br />
<br />
Private Sub cmdLast_Click()<br />
<br />
rst.MoveLast<br />
Text1.Text = rst.Fields(0).Value<br />
Text2.Text = rst.Fields(1).Value<br />
<br />
End Sub<br />
<br />
Private Sub cmdNext_Click()<br />
<br />
rst.MoveNext<br />
Text1.Text = rst.Fields(0).Value<br />
Text2.Text = rst.Fields(1).Value<br />
<br />
End Sub<br />
<br />
Private Sub cmdPrevious_Click()<br />
<br />
rst.MovePrevious<br />
Text1.Text = rst.Fields(0).Value<br />
Text2.Text = rst.Fields(1).Value<br />
<br />
End Sub
The code that you see above is do the following action:
1. Connect to Database, check if there is record in the database and show it in the text box.
2. Add the record in table.
3. Update the record in the table.
4. Delete record in the table.
5. Navigate through the record.
What I want is sample code to do the following action in VB.NET without using any Adapter control (SqlDbAdapter or OleDbDataAdapter, I need the code only).
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
|
hey guys... ive got this problem.. i dont know how simple this is but i just cant really get the value of my mfc dll returns to my vb app. everything works fine except when the data is of type BSTR.. i only get the first character of the string everytime i called the function in my vb app... i have this structure
struct udtAccessPointsInfo
{
BSTR sysIPAddress;
INT sysPortNumber;
BSTR sysAccessPointID;
BYTE sysStatus;
};
and a function that uses the struct....
LONG GetAccessPointsInfo([out, retval] udtAccessPointsInfo* pAccessPointsInfo)
inside the function i have this line of code for testing...
CString data = "1.1.1.200";
pAccessPointsInfo[0].sysIPAddress = data.AllocSysString();
when i tried to access the values of the struct in my vb app... i only get a string of value "1" which is the start of "1.1.1.200"... i really cant figure out what is really wrong... pls help me.. i think im really a mess with storing a CString to BSTR...
|
|
|
|
|
The code you posted is C#. You might want to try asking this question in the C# Forum.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is this a VB6 or a VB.NET question?
Is the DLL a straight MFC DLL or a COM DLL with MFC support?
|
|
|
|
|
its a vb.net question...but later i will transfer the code to vb6.. can i get both the answers in 6 and .net? its a com dll with mfc support... thanks a lot....
|
|
|
|
|
I hope it can wait for morning. It's 1:00am here and I'll have to dig out some code samples but it's not very hard. I'll post here tomorrow?
You can email me as well to touch base.
mattisking@pobox.com
|
|
|
|
|
thanks a lot... i think i can still wait.. its 1 pm here.. so i still have time till night today to finish it.. thanks!!
|
|
|
|
|
Send me an email if you need a coded example. Otherwise, try this instead:
CString data = "1.1.1.200";
WCHAR strMsg[MAX_PATH];
ZeroMemory(strMsg, MAX_PATH*sizeof(WCHAR));
mbstowcs(strMsg, (const char*)data.GetBuffer(), MAX_PATH);
pAccessPointsInfo[0].sysIPAddress = strMsg;
The only part that throws me a little is your structure. I couldn't "easily" set myself up a small test project passing that structure around... cause I can't remember how to do it because I gladly strode away from BSTR's and VARIANT's 2 years ago when I switched completely to C# and VB.NET. However, that should pretty much do it. I have lots of various examples and ways of doing this so let me know if that doesn't work for you.
|
|
|
|
|
it didnt work for me.... its still one character... i checked my return by putting a sprintf at my code...the whole string is being passed to my vb app.. but only the first character is being seen by the vb app..im sure im passing the structure correctly coz i can see the value of the integer type member of my structue returned... i got this code from one site.. instead of manipulating my mfc com dll.. it manipulates the vb code...its written in vb6 so i had to rewrite my code to vb6....
StringFromBSTR - Convert a BSTR to a VB string
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As _
Any, source As Any, ByVal bytes As Long)
' convert a BSTR into a VB String
Function StringFromBSTR(ByVal pointer As Long) As String
Dim temp As String
' copy the pointer into the temporary string's BSTR
CopyMemory ByVal VarPtr(temp), pointer, 4
' now Temp points to the original string, so we can copy it
StringFromBSTR = temp
' manually clear then temporary string to avoid GPFs
CopyMemory ByVal VarPtr(temp), 0&, 4
End Function
i guess a similar code like that will work for me... i've been trying that code but still no work... pls send me or post a similar code... thanks in advance...
|
|
|
|
|
Try this... this might not be good practice because you'd be allocating memory in C++ and I don't know that VB will clean it up or not...
but try changing your BSTR to BSTR*:
struct udtAccessPointsInfo
{
BSTR* sysIPAddress;
INT sysPortNumber;
BSTR sysAccessPointID;
BYTE sysStatus;
};
CString data = "1.1.1.200";
WCHAR strMsg[MAX_PATH];
ZeroMemory(strMsg, MAX_PATH*sizeof(WCHAR));
mbstowcs(strMsg, (const char*)data.GetBuffer(), MAX_PATH);
pAccessPointsInfo[0].sysIPAddress = SysAllocString(strMsg);
|
|
|
|
|
hi matt.. i cant change the structure they provided for me... it has to be like that.. anyways.. i've already told them about the problem.. still got one issue.. how do i pass an array of struct in vb.net? like for an example..
Structure AccessPointsInfo
Dim sysIPAddress As String
Dim sysPortNumber As Integer
Dim sysAccessPointID As String
Dim sysStatus As Byte
End Structure
Private Declare Function GetAccessPointsInfo Lib "Sample.dll" (ByRef AccessPt As AccessPointsInfo) As Long
i have to pass an array of struct... like... Dim AccessArray(100) As AccessPointsInfo.. i just couldnt find a way....
|
|
|
|
|
You'll need to look into VARIANT arrays. I can't really help you on that one. It's been too long but there are samples here on CP.
|
|
|
|
|
Hi All,
Please provide some clarity to my muddled brain.
I am new to VB.NET and am building some add on customisation to ESRI's ArcGIS suite. I have VS.NET 2003 and am building a VB Class Library project.
My code builds and runs without a hitch on my computer (win2K SP4) but when I build the setup program and deploy on another machine (WinXP SP2) my code installs alright and runs some sections fine, but falls over when it gets to a section requiring stdole saying stdole or one of its dependencys not found.
The target machine has .net 1.1 framework installed and on investigating my .net project I find that the detected dependencies in the setup project stdole is missing reference to mscorlib 1.0.330.0. (I could only find mscorlib 1.05000.0 on my machine)
Further investigation shows that stdole reference is to runtime version 1.0.3705 and file version 7.0.3300.0 yet when I check this file in win explorer it says the file version is 7.0.9466.0.
I can't find any other copies of this file on my machine. Am I somehow referencing a file that no longer exists?? should there be a 1.1 version of stdole??
I have searched and searched and have thus far come up blank.
Any help or explanations greatly appreciated.
Cheers
David
|
|
|
|
|
do you have references to any PIA's?
if you do did you install the latest ones?
|
|
|
|
|
stdole is under the \program file\microsoft.net\primary interop assemblies directory.
I have installed .net framework sp1.
As mentioned above, I am not sure if it is referencing correctly as the reference says file version 7.0.3300.0 but win explorer says stdole.dll file version is 7.0.9466.0.
|
|
|
|
|
are any of these missing from the Windows\System32 or WINNT\System32 folder:
stdole32.tlb
stdole2.tlb
stdole.tlb
|
|
|
|
|
Thanks for the quick reply.
All files exist on my machine under winnt\system32 and client machine under windows\system32
|
|
|
|
|
Mine is the same as yours and I have no trouble in deploying to a new machine. The problem must be somewhere else.
C:\Program Files\Microsoft.NET\Primary Interop Assemblies\stdole.dll
runtime version 1.0.3705 and file version 7.0.3300.0
explorer it says the file version is 7.0.9466.0.
|
|
|
|
|
If you add a setup project to a project with stdole as a reference.
Does the detected dependency refer to mscorlib v1.0330.0?? If so where does this live on your machine.
This is the dependency that seems to be missing from my setup project
I can only locate mscorlb v1.0.5000.0 which live under c:\winnt\microsoft.net\framework\v1.1.4322
|
|
|
|
|
I have these:
mscorelib version 1.0.3300.0 in:
c:\windows\microsoft.net\framework\v1.0.3705\mscorlib.dll
mscorelib version 1.1.4322.2032 in:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscorlib.dll
mscorelib version 1.0.2268.0
C:\Program Files\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows CE
if I add the reference to stdole it shows the 1.0.3300.0 version.
|
|
|
|
|
Thanks. I think I'm starting to get somewhere now.
I have loaded .Net Framework 1.0 which has put the file back on my computer under \microsoft.net\framework\v1.0.3705\mscorlib.dll.
It still refuses to pick it up as a dependency and if I add it as a reference (via browse) to the source project I get a message saying it will change where System etc are referenced from and if I agree I get heap of 'Object' is ambiguous in the namespace 'System' type errors come up in the tasks.
I am going to try a reinstall of VS.NET 2003 now that I have .NET Framework 1.0 installed and see if stdole references mscorlib properly.
If I am still having problems I will reply again.
|
|
|
|
|
This is driving me crazy.
OK step by step this is what I do.
I have a VB.NET class library with varios forms and classes, one of which uses stdole.IFontDisp
The solution builds and runs like clockwork on the development machine.
I add a setup project so that I can distribute the dll in a .exe file.
I set the Project Output of the Setup Project to be the source project mentioned above.
When I look at the Detected Dependencies, stdole is missing a dependecy mscorlib 1.0.3300.0
I am sure it exists on my computer now, I am at a loss.
|
|
|
|
|
Ok, I think I may know what the problem is, if you'll bear with me for a bit.
I mushed around thru microsoft's site a bit and found a lot of references about the stdole.dll you are trying to distribute, it is the developer version and that's not supposed to be re-distributed, you reference it in a build when you use the office interops but as far as I can tell the IDE is not supposed to add it to the dependency list because it is installed with the net framework re-distribution. The only one allow to be re-distributed is the runtime version. If your still following all this the a solution may be to download the re-distributable pia's to your machine move the stdole.dll file to your app bin directory and reference it instead, make sure your software works then add it as the dependancy.
This is just a shot in the dark, because, one, I have never had that problem, and two, my IDE say's the same thing your's does, and I have no stdole problem with my builds that include it, as it never get's packaged in the msi file.
|
|
|
|
|
Thanks again.
Are the redistributable PIA's part of the .NET redistributable (dotnetfx.exe).
Should I be thinking then that this is more an issue with the client machine and digging deeper there?? Although I am sure .NET 1.0, .NET 1.1 and Office XP PIA's are installed.
I'll get back to you with any results.
Cheers
|
|
|
|