Err! I have found it. The problem is occurring just because I changed the database path to application.startuppath. It was working fine when it was in its default path. So, can you please tell me what should I do in this moment?

I've found it. The problem is occurring just because I changed the connection string to application.startuppath. It was working fine when the project folder was on the desktop and connection string was set to like, users\desktop\project folder\\ etc. So, can you please help me to keep the database in the debug folder and use it by application.startuppath?

You don't need to use AttachDbFilename in your connection string. But you need to add database name such as following
Database=myDataBase;
Also, please use try/catch block to get an exception messages.

1 solution

Solution 3

0) Please put all the data access code in a separate class -- a Data Access Layer.
1) Please use a parameterized query; do not use concatenation to form your queries.
2) Do not open the connection and leave it open for the duration of the application.
3) Use a try/finally
4) Your click will close the connection and a second click will fail.