|
OK. You've got a huge spaghetti problem here. For example, just look at the single line of code in your Form's Load event handler.
GetConnectionString()
Now, I'm all for self-documenting code and the name you chose for this method is pretty decent, but I would expect a method with that name to actually return a connection string. Your GetConnectionString method does everything BUT return a connection string! Why do you have a method with this name creating a DataTable, creating columns in it, opening a connection, executing an SQL command, filling that DataTable, and NOT returning a connection string?
You have this problem throughout this bowl of noodles you call code and it's this very problem that's causing your issues now that you want to change one little piece of functionality.
This stuff should be broken down into more methods, seperating and encapsulating functionality. You got the first method name correct, GetConnectionString . Now make it actually return a connection string!
Public Class DatabaseLayer
Private Shared Function GetConnectionString(ByVal filename As String) As String
' Build the full path to the specified database file and see if this
' file exists
Dim fullPath As String = Path.Combine(Application.StartupPath, filename)
If Not File.Exists(fullPath) Then
Throw New FileNotFoundException("Unable to locate the database file {0} in the application folder.")
End If
' Get the connection string template
Dim connStringTemplate As String = My.Settings.ConnectionString
' Build and return the completed connection string
Return String.Format(connStringTemplate, Path.Combine(Application.StartupPath, filename))
End Function
Private Shared Function CreateDatabaseConnection(ByVal filename As String) As OleDbConnection
' Get a connection string for the specified database file
Dim connString As String = GetConnectionString(filename)
' Return an OleDbConnection object
Return New OleDbConnect(connString)
End Function
Private Shared Function GetFileExcludeTableSelectCommand() As OleDbCommand
Dim selectSql As String = "SELECT " & _
"ExcludeID, ExcludePath, ExcludeFileName FROM tblExclude"
Return New OleDbCommand(selectSql)
End Function
Private Shared Function CreateFileExcludeTableDataAdapter(ByVal selectCommand As OleDbCommand, ByVal connection As OleDbConnection) As OleDbDataAdatper
Dim da As New OleDbDataAdapter(comm, conn)
' Put code here to add any command parameters and use the OleDbCommandBuilder
' to finish building the DataAdpters UPDATE, DELETE, and INSERT commands.
Return da
End Function
Public Shared Function GetFileExcludeTable() As DataTable
Dim dt As New DataTable("FileExcludeTable")
Dim conn As OleDbConnection = CreateDatabaseConnection("File.mdb")
Dim comm As OleDbCommand = GetFileExcludeTableSelectCommand()
Using da As OleDbDataAdapter = CreateFileExcludeTableDataAdapter(comm, conn)
da.Fill(dt)
End Using
Return dt
End Function
This is just a small SAMPLE of a data layer, meant to demonstrate encapsulation and modularization.
|
|
|
|
|
Ok, this is very helpful but it still does not solve the problem.
Database Table
ExtID
(AutoNumber)
ExtType:
.wmv;.wav;.mp3;.exe
Currently my program search for file extensions by entering the extension into a textbox, for example wav;mp3;exe. Whatever extension is typed into textbox the program will look for those extensions. How can I search for specific file extensions from the ExtType column in database istead of entering the ext in the textbox? I have the field where all of the extensions are in one column.
|
|
|
|
|
jds1207 wrote: this is very helpful but it still does not solve the problem.
Wanna bet??
The problem you're running into is that all of this code is attached to a button event handler. You have to break this code out so it's not dependant on the UI click events at all. The code needs to be refactored to seperate the functionality from that TextBox. The search function needs to be able to stand on its own and do it's job just by passing the extensions to a method to start the search. Once you seperate this search code from the UI, your problem is 95% solved.
|
|
|
|
|
How To use a component that is present outside the current working environment.
How deos the DataAdpter,DataSet work together in establishing connection between VB.NET and SqlServer2005.Explain with example
trustworthy
|
|
|
|
|
somunu wrote: How To use a component that is present outside the current working environment.
No idea what you mean
somunu wrote: How deos the DataAdpter,DataSet work together in establishing connection between VB.NET and SqlServer2005.Explain with example
ADO.NET works in a very simple and well defined way - some classes handle connecting to the DB, others handle creating a representation of the data returned. Have you got any books on the topic ? Have you tried google ?
What you're asking is not clear, in both cases.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hi All
i want to Deploy my application, am using Access as my backend.i have included the DB with the application. but now when i install it on a client's machine it reqiures a Database to be in
C:Programfiles\Development For One\Search_Property
How do i Deploy my Application, when it is being installed on a client machine, it should have the correct mappings?
PLease provide Articles or Explanation.
Thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding
|
|
|
|
|
Vuyiswamb wrote: it should have the correct mappings?
What do you expect the "correct mappings" to be?? Where did you want the database to be?? What does the code look like that builds the file path to the database?? Or did you make the mistake of hard-coding the path to the database into your application??
|
|
|
|
|
Dave Kreskowiak wrote:
|What do you expect the "correct mappings" to be??
When i install it in a client machine, it will go to c:\Programfiles\MYApp\mydb.mdb. but now it is looking for that DB in same location where i was Developing. what if i was Developing this application and Saved all my Projects under a different Drive like G:,when i install it in my client machine it will look for a the db in G: drive.
Dave Kreskowiak wrote:
Where did you want the database to be??
i want it to be in the Application Folder, yes i can achieve that, but now, even if i put it in the application folder, it will still look for in my Development drive. i have used a wizard to make a connection to my database and the Db is in my application development directory.
Dave Kreskowiak wrote:
What does the code look like that builds the file path to the database??
i used a Wizard to achieve this, so i did not hardcode the DB mappings
Thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding
|
|
|
|
|
Vuyiswamb wrote: used a Wizard to achieve this, so i did not hardcode the DB mappings
Yes, you did, by using the Wizard. The full path to the database is probably going to be in the connection string stored in either your application Settings or in your app.config file. I don't know which because I don't use the wizards to do my database work.
|
|
|
|
|
i will remember that.
thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
|
|
|
|
|
I'm getting an error when i load the crystal viewer and my report source is a crystal report that has a datasource of a dataset.
The error is "Error in File C:\Docu~\\temp_7232f9...rpt: Query Engine Error."
The things that I did was I created a crystal report in .net. I have a crystal 9 developer edition installed in my computer. When I tried to run Custom Tool I got an error. so I changed crystaldecisions.vsdesigner to crystaldecisions.vsshell. Then I created a dataset. When I'm trying to add in crystal report the dataset i got an error. so I add in my reference vsdesigner.dll from the crystal report 9 folder in my program files. after that i can already add the dataset in my crystal report. but when i run the viewer and set my report source to my crystal report i'm getting the error "error in file c:\Docu~\\temp....".
Can someone help me to solve the problem without uninstalling the existing crytal report in my system?
|
|
|
|
|
hi all,
i am trying/wanting to just remove or delete a record or element from my array. i have been spending too much time on this area and want to move on. i don't want to use the arraylist syntax because i want to know how to do the removing using a static array.
my array is: arrBooks(20)
any kind of help is much appreciated. thank you
Unicept
|
|
|
|
|
you can use Array.Clear to remove the item, then if you wish you could always resize the array ( you don't have to do that part tho )
eg:
<font color="#008000">'/// say i wanted to remove item 15 in the array<br />
''/// i'd specify the index of the item to remove as 2nd parameter ( 15 in this case )<br />
'/// i'd specify the amount of items to remove from that point as 3rd parameter ( ie: 1 item to remove just position 15 )</font><br />
Array.Clear(arrBooks, 15, 1)<br />
<font color="#008000">'/// then if you wish to resize the arrBooks to account for the deleted item ( s )</font> <br />
Array.Resize(arrBooks, " the new size here as an integer " )
hope it helps
<--- my signature --->
<font color="blue">Csharp</font> me = (<font color="blue">Csharp</font>)Dynamic_Sysop; <font color="#008000">// My Signature.</font><br><font color="#008000">$twins</font> = <font color="#008000">me.twins</font>(<font color="#800080">"Taylor"</font> , <font color="#800080">"Delta"</font>); <font color="#C0C0C0">// My twin daughters.</font><br>echo <font color="#008000">$twins</font>;
|
|
|
|
|
Simply, you can't. If an element is in the middle of an array, you need to create a new array that is one element smaller, and copy the elements you want, across. Even if it's the first or last item, you need to do this, it's just one copy then. That's what arraylist is for, because you have to recreate your array to remove an item from it.
If you know the right tool for the job, why would you insist on trying to use something else ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
If you are using .net 2.0 and want this functionality available easily you can use a generic list
Dim books As Generic.List(Of myType)
Dim item as new myType
'Add an item to the list
books.Add(item)
'remove an item from the list
books.Remove(item)
'Remove item at index from list
books.RemoveAt(1)
Hope that helps
|
|
|
|
|
Hi
I have done this in my previous project successfully. Now I am doing this again on my current project and it does not display groups. although ShowGroups property is set to true with view property = details.
The code is
Dim lg As System.Windows.Forms.ListViewGroup = lvAll.Groups.Add("abc", "abc")
Dim lstSC As New ListViewItem("xyz")
lstSC.SubItems.Add("xyz1")
lstSC.Group = lg
lvAll.Items.Add(lstSC)
' where lvAll is listview name
I copy pasted the listview control from my previous project incase I am missing any property but it does not work.
Any Suggestions would be highly appreciated.
Regards
|
|
|
|
|
ListViewGroups only work on XP or above. They don't work on Windows 2000 and below. In addition, you're application must have previously called Application.EnableVisalStyles() and the ListView's View property must be set to anything other than View.List in order for groups to work.
|
|
|
|
|
Many Thanks.. It works
|
|
|
|
|
i m developing an application and 50% completed bt the memory usage at this time is too high its abt 40MB y is that so? how can i solve the problem?
(Jameel)
|
|
|
|
|
use less memory.
What other advice did you hope for, you've not descibed your app at all. 40MB is not a whole lot, given that it includes the runtime. I think you need to just relax, in all likelihood
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Is there any spacific shared folder in windows for which every(admin,guest,other etc) user have write/read access....
(Jameel)
|
|
|
|
|
jamilkhan007 wrote: spacific shared folder in windows for which every(admin,guest,other etc) user have write/read access....
Wouldn't System Temporary folders (TEMP) satisfy this criteria? But I don't think they are by default shared, unless you share them explicitly or through an Administrative Share.
|
|
|
|
|
Shared folders?? No, there are none.
You'd have to create a folder, Share it yourself, and set the appropriate permissions on the Share and NTFS sides.
|
|
|
|
|
where do different applications store there file which have to be read/write by different users on the target machine???? my app stores an xml file which contains users password,names etc. and this file placed under C:\prog-files\myapp\users.xml. bt when app tries to write to this file and "access denied" exception is thrwon. Now i hope u can help me in a better way....
Heartly Thanx for all of u frnds.
(Jameel)
|
|
|
|
|
Either in the applications Program Files folder or in
Program Files\Common Files\manufacturer\appname
|
|
|
|