|
Hi, i've got this form which connects to database during form load. i'm using relative path connection.however, after i convert this form to a userControl, i can't add this userControl. it says that the program can't locate my database in this address: C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\myDataBase.mdb. But i did not do my work in that address!! so why would it look for my database there? But if i change my connection to a absolute path, it works. is it possible i remain using a relative path while using userControl.
chris
|
|
|
|
|
The problem you have is that your using relative paths! Don't ever do this! Your assuming that the current directory is the one that the application is started from. THis is almost never the case! Instead, build an absolute path to your database using the Path.Combine method and the Application.StartupPath property:
using System.IO;
.
.
string absDBPath = Path.Combine( Application.StartupPath, "mydatabase.mdb" );
Also, it's very bad practice to have an application hold open a connection to a database, or any other resource for that matter, for the life of the app or control. When using expensive and scarce resources, such as database connections, ALWAYS open the connection as late as possible, do your database work, then close and release the connection as early as possible. Holding open a connection to the database wastes money and memory on the server. Since your application spends 98% of its life idling, you're hogging a connection license and memory on the server and doing nothing with it!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi, sorry i think you made a mistake. the connection that your talking about is relative path which i'm using. this is my coding:
OleDbConnection conn = new System.Data.OleDb.OleDbConnection(); conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +<br />
@"Data source = "+Application.StartupPath +@"\myDatabase.mdb";
the current directory i'm working in is (C:\Documents and Settings\020670F\My Documents\020670F\FYP backup\SingaporeCrusieCentre\bin\Debug\myDataBase)
as i've mention earlier, after i convert my form to a userControl, i can't add the userControl i've created. it says that it cant locate my database in (C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\myDatabase). i'm confused because i did not do my project in that directory. it works after i use a absolute path connection. Please Help. Thanks
Chris
|
|
|
|
|
nuttynibbles1984 wrote:
the connection that your talking about is relative path
No, it's not. Application.StartupPath returns a completely qualified absolute path, starting with a drive letter. A relative path would look something like "..\..\subDir1\subDir2\myDatabase.mdb".
Hmmm...I don't know what you did. When I used Application.StartupPath , I got the path to the bin folder in my project folder. Something like this:
"C:\Documents and Settings\[userID]\My Documents\Visual Studio Projects\RegistryAccess\bin"
This worked in either a Windows Forms project or in a Control Library project. In the later case, it always returns the path to the application that is hosting the control.
BTW: What do you mena you "converted" your app from a Windows Forms project to a Control project? What did you do?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
there's two way to use userControl. 1) to add a new project and select add user Control. 2) if you have create a form and did some coding, you can change this form to a user control by changing System.Windows.Forms.Form to System.Windows.Forms.UserControl at the very top just after the namespace.
namespace Form1<br />
{<br />
<br />
public class Form1 : System.Windows.Forms.UserControl
{<br />
}<br />
}
anyway do you want me to send a sample program to you and mayb you can see what i mean.??
Chris
|
|
|
|
|
i am planning for the development of a peice of software designed to use a dbms, thing is, i don't want to lock it down to any specific dbms, so the idea was that i would design an interface, and provide some implementations. The idea is that, out of the box, one can easily select a variety a dbms to use, and the option is there for developers to write their own implementations.
now, how can i enumerate and allow selecting of interface implementations? there must be a way?
|
|
|
|
|
Hi,
im doing a log file parser in c#. i have finished. but when come to the performance it is very slow to handle 40,000 lines in a log file. how can i improve the performance.
im using a string manager class which adds the string to the hashtable if the string is not there. otherwise it returns the already existing string index. in the hashtable, i have used int value as a key and value as a StringBuilder.
when it searches the hashtable for a specific string using ContainsValue it takes the most of the time.
any solutions to improve this.
thank u.
|
|
|
|
|
Here you need to manipulate with lot of string values. String in immutable in nature . In this sort of senario StringBuilder class is ideal . Please check the properties and Methods of StringBuilder class which avilable in System.Text namespace and all members of this class are self explanatory in nature(MSDN). And apply little logic to achive your result.;)
Sreejith Nair
[ My Articles ]
|
|
|
|
|
hi,
Thank u Mr.Nair.
yes i have done it. now im using a hashtable and it is faster. but there is one more problem. serialization takes much time than parsing the file.
after parsing all the files, i add all the files in an ArrayList and then i gave that arraylist to serialize. i used the serialization at the end.
help me out.
thank u.
|
|
|
|
|
Insted of ArryList Try to use SortedList and compare the performance.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
I want to invoke the DeviceIoControl() API in C#,then how to define IOCTL_SCSI_PASS_THROUGH ?
//vc++ code :
DeviceIoControl( hFile, IOCTL_SCSI_PASS_THROUGH, &SPTWB, length,&SPTWB, length, &dwBytesReturned, FALSE );
Thanks!
|
|
|
|
|
|
//vc++ code:
......
int *point,low;
point1 = &low;
point = point1;
if (point == null)
{......}
......
How to convert this to C#?
|
|
|
|
|
CLR won't execute the code which is unsafe. Here your requirement is to execute this unsafe code.
For executing unsafe code in managed environment you have to use unsafe keyword.
Eg:
<br />
<br />
using System;<br />
<br />
namespace ConsoleApplication1<br />
{<br />
class Class1<br />
{<br />
public static unsafe void CopyMethod(byte[] src,int cntsrc,byte[] dnc,int cntdnc,int count)<br />
{<br />
if(src==null||cntdnc<0||dnc==null||cntdnc<0||count<0)<br />
throw new ArgumentException();<br />
int srclen=src.Length;<br />
int dnclen=dnc.Length;<br />
if(srclen-cntsrc<count||dnclen-cntdnc<count)<br />
throw new ArgumentException();<br />
fixed(byte* pSrc=src, pDnc=dnc)<br />
{<br />
byte* pscr=pSrc,pdnc=pDnc;<br />
for (int n = count >> 2; n != 0; n--)<br />
{<br />
*((int*)pdnc) = *((int*)pscr);<br />
pdnc += 4;<br />
pscr += 4;<br />
}<br />
for (count &= 3; count != 0; count--)<br />
{<br />
*pdnc = *pscr;<br />
pdnc++;<br />
pscr++;<br />
}<br />
}<br />
}<br />
<br />
static void Main(string[] args) <br />
{<br />
byte[] a = new byte[100];<br />
byte[] b = new byte[100];<br />
for(int i=0; i<100; ++i) <br />
a[i] = (byte)i;<br />
CopyMethod(a, 0, b, 0, 100);<br />
Console.WriteLine("The first 10 elements are:");<br />
for(int i=0; i<10; ++i) <br />
Console.Write(b[i] + "{0}", i < 9 ? " " : "");<br />
Console.WriteLine("\n");<br />
}<br />
}<br />
}<br />
The above example uses pointers to copy an array of bytes from src to dst.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
Hi!Nair,
Thank you for your good example.
I can learn something from this sample code.
So what about the upper two problems?
Thanks!
momer
|
|
|
|
|
can anybody guide me how I can access email account settings like pop3 server,smtp server email address which are stored in ms outlook through c# so far i am able to access default folder of outlook like contacts inbox notes etc.is there any way to access these entries.
Thanking You,
chintan
|
|
|
|
|
|
thank you sreejith..for your reply..but this article give information about the things which i have already done like accessing inbox,notes,contacts..I am still not able to access email account settings of outlook through c#.could you guide me bit more so that i can get the email account settings..
thanking you,
chintan
|
|
|
|
|
Hello,
I have been trying to convert a ulong into it's component bits.
Unfortunately there is no converstion operation, and using pointers this is not possible, since there is no pointer of size 1 bit.
I have also tried the BitArray operation, but this only allows for int32 size variables... so I converted my ulong into 2 ints. However the result was not correct.
Now I do not have any ideas how to proceed.
Could somebody pls help me?
|
|
|
|
|
A combination of masking and shifting will work. For example:
ulong ulValue = 0xF345612347892019UL;
ulong ulMask;
int iBitValue;
for ( int iBit = 0; iBit < 64; ++iBit )
{
ulMask = 1UL << iBit;
iBitValue = (int)((ulValue & ulMask) >> iBit);
System.Console.WriteLine( "Bit {0}: {1}", iBit, iBitValue );
}
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
How to add small pictures for a chat windows (emptions )by shortcut.Buzz type of utility. like this
Learner always
|
|
|
|
|
Hi guys,
just a quick question.
This is my first time ever using GDI+ and C# for graphical output.
I have a Windows Form with 3 Panels, one docked to the middle (center) and 2 docked to the bottom. I use these panels to render graphs and rulers.
If I resize my Window, everything seems to be ok, the panels have a new size (larger or smaller) and look alright. But if I try to draw my graph or render my text, the renderer seems to be only using the "old" width" and height, not the additional area provided by the resize.
Well, I could always prevent the window from being resized, but that is really no help
If you could give me any hints, i would be very grateful.
Cheers
Sebastian
|
|
|
|
|
Try to invalidate the panel after before maximizing from minimized state.
That is call panel.Invalidate() to invalidate the panel region when user choose maximized.
And get back to me if this answer don't serves you.
|
|
|
|
|
Try to invalidate the panel after before maximizing from minimized state.
That is call panel.Invalidate() to invalidate the panel region when user choose maximized.
And get back to me if this answer don't serves you.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
Sorry, that did not work :/
Any other ideas?
Cheers
Sebs
|
|
|
|