|
Hello,
I am writting an aplication in VB.NET (not a website)
I would like to cache a datatable to save time when loading program, I will fill the datatable according to cache.
Here my code:
Imports System.Web.HttpRuntime
dtSynchronize = DirectCast(Cache("dtSynchronize"), DataTable)
If dtSynchronize Is Nothing Then
dtSynchronize = New DataTable
dtSynchronize.Columns.Add("EntryID", System.Type.GetType("System.String"))
dtSynchronize.Columns.Add("SyncData", System.Type.GetType("System.String"))
dtSynchronize.Columns.Add("StoreID", System.Type.GetType("System.String"))
End If
dtSynchronize.Rows.Clear()
dtSynchronize.Rows.Add("1", "2", "3")
Cache.Insert("dtSynchronize", dtSynchronize)
It works fine but when I am closing the application and opening it again, I expect that after the first line of code the dtSynchronize will not be Nothing but it is.
The cache is not saved.
Thank you
Shay Noy
modified on Tuesday, September 8, 2009 5:41 AM
|
|
|
|
|
I found other solution by storing the datatble in a file and it works fine. Although, if someone has solution for storing it in a cache, please advise
Thank you
Shay Noy
|
|
|
|
|
As a cache is only an area of memory it will disappear when your application closes unless you save it to disk or a database
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Thank you, I understood it later, I though it is the same cache like in ASP.net.
Shay Noy
|
|
|
|
|
Hi, I am fairly a newbie to vb.net and am developing an inventory control windows application for a client.
I am creating a search form for my application. This search form searches the categorys table and returns the results in a datagrid view. The search bit of it is working, however what i want it to do next is not working!
I have a button on the Search form called "Return Data". Once the search results have been displayed in the datagrid view, the user will then select/highlight the row that they need. They will then click on the "Return Data" button and this button should then return the selected row in the datagrid view and display it in another datagrid view on another form.
I am just finding it extremely difficicult to getting this sorted. I have not got anywhere with it. Any sample code would be most appreciated.
Thanks
|
|
|
|
|
ShabRaza wrote: Hi, I am fairly a newbie to vb.net and am developing an inventory control windows application for a client.
I pity the person who uses an inventory system written by a newbie. The world is insane.
ShabRaza wrote: Once the search results have been displayed in the datagrid view, the user will then select/highlight the row that they need. They will then click on the "Return Data" button and this button should then return the selected row in the datagrid view and display it in another datagrid view on another form.
The can select more than one row ? This Ui sounds odd, but you can iterate over your rows and check which have the selected property set to true.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I pity immature people like you who make assumptions about others on a flip of a coin.
I wanted advice on helping me resolve a problem, not having someone make a dig at me. In the end you werent much useful and next time keep your opinions to yourself!
|
|
|
|
|
|
To Hurricane3000
First of all i would like to ask, who involved you in this conversation? cos i sure as hell didnt. The comment i made was only intended for the person who made those comments to me and I dont remember asking anyone else's opinion!
After having some difficulty reading your message, i think you need to go find out and evaluate the difference between a "playful comment" and "personal offence". Since when does it make a difference on your programming ability if you are "unable to understand difference between a "playful comment" and a "personal offence"! ". I think you need to get your head checked out. I think being a good programmer is dependant on your technical ability amongst other IMPORTANT factors and not minor and irrelevant things.
I do not wish to carry this conversation any further as it is pointless. so if you have any sense dont reply back.
|
|
|
|
|
I wish you to end soon your program ShabRaza.
Good night.
|
|
|
|
|
Hello
Are you having ID filds in DGV.If you having then u can easly send selected rows into another dgv on another form.
When you select that row then just get id of that row, and when return data button is clicked then add new row on other dgv and send value from one dgv to another dgv.
The another method is that check which row is select using selected = true. Create object of another form and access DGV using anohterformobj.Datagridview. and add selected records on another dgv.
Regards
DC
|
|
|
|
|
Actually their are several ways to do this depends upon the criteria and structure of the application
lets suppose you need to show
=-=-Item Code=-=-=-=-Item Name=-=-==-=-category Name=-=-=-=-=-=-Units=-=-=-=-=-=-Qty
on the Destination form then on your Search/Lookup Form you can have some other columns like
=-=-Item ID======Category ID-=-=-=-=--
but hide them along with your other columns and dont show them to the end user when user will select any row then it will bring with it that item id, category id etc.. take only Keys as hidden columns
you can take this id and then can make a query to get your desired results and can populate your fields,
will not recommend you to open Costly connections again and again means to go to the database and bring your information time to time
Dont bring information other then Keys in hidden columns because if their will be any change on that data lets say you had populated in your grid and some other user changed the item Name or some other information in this case you will have still old value in the grid so bring only the IDs as hidden column and then fetch your desired data from db
Best Of Regards,
SOFTDEV
Sad like books with torn pages, sad like unfinished stories ...
|
|
|
|
|
Hi all.
I am trying to check whether a process has terminated or not by its process id.
I put my code in a timer object to continuously check whether process has terminated or not.
code is :
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Process.GetProcessById(ProcessID).HasExited Then 'processId is publicly defined and doesn't store null value
Cursor = Cursors.Default
Timer1.Dispose()
msgbox("Process has been terminated")
End If
End Sub
but each time timer starts, it gives an "Access is Denied" error message at line
If Process.GetProcessById(ProcessID).HasExited Then
what should I do to check whether the process has terminated or not.
Thanks.
Gagan
|
|
|
|
|
Hi,
if you are logged in as a regular user and try to get information on a process that isn't yours, Windows will give you an "access denied" error (at least on Vista and 7, not sure for others). In general you have no rights on objects that don't belong to you.
BTW: An admin has no problems, Process.Exited does not need elevation.
|
|
|
|
|
Thanks Luc for your help but I already logged as "Computer Administrator"
(in Windows XP) but the same problem occurs all the time.
process.HasExited 'Access is Denied.
Is there any other way to check whether process has terminated or not, if yes then tell me.
Thanks.
Gagan
|
|
|
|
|
What process is it you want to check? Dit your app launch it?
Your code works fine for me checking my browser.
|
|
|
|
|
I am executing "cmd.exe" and getting its process id to check whether "cmd.exe" has terminated or not but all the time it gives the same "Access is Denied" error message.
|
|
|
|
|
Hi,
two suggestions:
1.
For processes that your app started, choose one of several Process.Start overloads that return a Process instance, so you don't need Process.GetProcessById()
2.
Rather than periodically checking Process.HasExited, you could have a thread (Thread, ThreadPool, BackgroundWorker) wait for its exit with Process.WaitForExit which also needs the process instance.
|
|
|
|
|
I have a table populated with details of people (Name, tel, address, etc.) Each record has a unique key. I want to fill a combobox with the names, but when a user clicks on the name I want to use the unique identifier to get the corresponding detail. Below is my code to fill the combobox. How should I change this so that the combobox also knows what the unique identifier is?
I am new to programming, so any other comments on my code would also be appreciated.
Thanks for any help.
Private Sub GetContactNames()
Dim SqlContactname As String _
= "SELECT _rtblPeople.idPeople, _rtblPeople.cDisplayName " _
& "FROM _rtblPeople, _rtblPeopleLinks " _
& "WHERE _rtblPeopleLinks.iDebtorID = @customercode " _
& "AND _rtblPeopleLinks.cModule = 'AR' " _
& "AND _rtblPeople.idPeople = _rtblPeopleLinks.iPeopleID"
Dim Sqlparam As SqlClient.SqlParameter
Sqlparam = New SqlClient.SqlParameter("@customercode", SqlDbType.Int)
Sqlparam.Value = My.Settings.CustomerCode
Using conn As New SqlConnection(CntString)
Try
conn.Open()
Dim MyCommand As New SqlCommand(SqlContactname, conn)
MyCommand.Parameters.Add(Sqlparam)
Dim datareader As SqlDataReader
datareader = MyCommand.ExecuteReader
While datareader.Read()
ContactNameField.Items.Add(datareader.Item("cDisplayName"))
End While
datareader.Close()
conn.Close()
Catch myerror As SqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
conn.Dispose()
End Try
End Using
End Sub
|
|
|
|
|
Hi,
you could create a little class describing an item in the combobox.
Then tell the ComboBox where the list of items is (DataSource), which property to use for displaying (DisplayMember) and which one for processing (ValueMember).
MSDN holds examples for all this.
|
|
|
|
|
OK, I think I managed to create the class and it seems to work, except when I have names in the combobox that are identical. Say I have values John(1), Paul(2), John(3). When I select the first John other fields on the form is refreshed using the correct value (1). When I select the second John it also works fine using the correct value (3). The problem is when I leave the comboxfield another SelectedIndexChange is fired and the value then changes to (1). When I select Paul I have no problem.
Here is the class I created - I copied the format from sample code:
Public Class myLookupClass
Private iID As Integer
Private sValue As String
Public Sub New(ByVal DisplayValue As String, ByVal ID As Integer)
iID = ID
sValue = DisplayValue
End Sub
Public Property GetLookup() As Integer
Get
Return iID
End Get
Set(ByVal value As Integer)
sValue = value
End Set
End Property
Public Overrides Function ToString() As String
'Return MyBase.ToString()
Return sValue
End Function
End Class
I populate the combobox like this
While datareader.Read()
ContactNameField.Items.Add( _
New myLookupClass((datareader.Item("cDisplayName")), _
(datareader.Item("idPeople"))))
End While
Any thoughts on were I am going wrong?
|
|
|
|
|
In some way, the names that you are showing (display values) should be unique. If there are going to be two or more the same, how will the user know which one he should pick?
In other words, if you solve that problem, you also won't have this problem.
My advice is free, and you may get what you paid for.
|
|
|
|
|
They would be unique most of the time, I am just trying to cover all possibilities. That is why I created the class to work with the ID of each field (which is unique). As the user selects a field, other fields on the form refresh to give them more info of the selected person so they will know who they selected even if the names are the same.
|
|
|
|
|
In that case you could use one of two workarounds:
1. The AchoiceWasMade boolean, to check whether the selected index was changed by the user. That way you circumvent the event firing twice.
or
2. Change the display value to include a number, for example the way you did in the original problem description: John (1) and John (2).
So you make the display value unique, and it would only make things clearer for the user.
My advice is free, and you may get what you paid for.
|
|
|
|
|
I like your first option - If I cant get it to work, i'll have to use the second option.
Thanks for the replies.
|
|
|
|