|
Psycho-*Coder*-Extreme wrote: could literally insert up to 65,000 rows
Are you Inserting from within a loop? Or Are you using a Stored Procedure? Please make it clear..
Anyway, if you are doing the DML inside the loop, then there sure is a chance
The name is Sandeep
|
|
|
|
|
Iam using a Stored Procedure, but it is an INSERT INTO....SELECT FROM Stored Procedure.
"Okay, I give up: which is NOT a real programming language????"
Michael Bergman
|
|
|
|
|
Hi,
Usually I used image animation like windows when copying file.
GoodID
|
|
|
|
|
I am using the DataGridView unbound but now I have need to present boolean information to the user with the DataGridViewCheckBox class. Normally I format a DataTable and populate a datarow into that table like thus as below, but when I add the DataGridViewCheckBoxColum in, I cannot populate the DataTable it has to be inseerted into the grid itself. Any help would be appreciated.
Dim column As New DataGridViewCheckBoxColumn(), rDesc As New DataColumn(), tb as New DataTable
With rDesc
.DataType = System.Type.GetType("System.String")
.ColumnName = "Description"
.Caption = "Description"
.ReadOnly = True
End With
Me.tb.Columns.Add(rDesc)
//Problem Area
With column
.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
.FlatStyle = FlatStyle.Standard
.CellTemplate = New DataGridViewCheckBoxCell()
.CellTemplate.Style.BackColor = Color.Beige
End With
DataGridView1.Columns.Insert(0, column)
Me.DataGridView1.DataSource = tb
Dim r As DataRow
r = tb.NewRow()
r(0) = "hello"
tb.Rows.Add(r)
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones."
Einstein
|
|
|
|
|
I can't seem to dispose of a singleton object that my web page has created. Here is the class code:
Public Class Class1
Implements IDisposable
Private Shared myInst As Class1
Private Shared myMutex As New System.Threading.Mutex
Public Shared myVal As Integer
Private Shadows disposed As Boolean
Public Shared Function GetInstance() As Class1
myMutex.WaitOne()
If myInst Is Nothing Then
myInst = New Class1
End If
myMutex.ReleaseMutex()
myInst.myVal += 1
Return myInst
End Function
Public Sub Dispose() Implements IDisposable.Dispose
If Not disposed Then
disposed = True
GC.SuppressFinalize(Me)
End If
End Sub
Public Shared Sub DisposeIt(ByVal Cls1 As Class1)
Cls1.Dispose()
End Sub
End Class
In my web form, I have this code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myclass1 As Class1 = Class1.GetInstance
Class1.DisposeIt(myclass1)
Response.Write(myclass1.myVal)
End Sub
When I run this program, the object will be created and myVal will be incremented every time the program is run, whether I close the browser beforehand or not. In other words, the "Class1.DisposeIt(myclass1)" statement simply doesn't dispose of the object in memory. I am trying to understand singleton objects and disposing of them, but I am missing some critical concept here. Any help would truly be appreciated.
|
|
|
|
|
You have misunderstood the meaning of disposal. To call the Dispose method doesn't remove the object from memory, it's just used to tell the object to prepare for removal. As long as you are holding on to the reference to the object, it will not be garbage collected. As you are not really doing anything in the Dispose method, the object will keep working eventhough Dispose is called repeatedly.
If you want the object to be released, you have to set the reference to Nothing. Then a new object will be created the next time GetInstance is called.
If your object will not contain any unmanaged resources, there is no reason to use the IDisposable interface at all. Just set the reference to Nothing, and the garbage collector will take care of it.
---
single minded; short sighted; long gone;
|
|
|
|
|
Thanks Guffa, and what you say about setting the reference to Nothing was my original understanding, but it didn't seem to work, which lead to my wrong path down the Dispose lane. Here was my original code from my calling program:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myclass1 As Class1 = Class1.GetInstance
Response.Write(myclass1.myVal)
myclass1 = Nothing
End Sub
Now, when a person opens his browser, he will see the value "1" displayed on his screen. Open another browser instance, and he will see "2", and so on. Even though the reference was set to nothing, the second browser instance will use the shared value from the object that is supposed to be Nothing. Ok, I can't tell when the garbage collector would have released it from memory, but it seems to me that the second browser instance shouldn't have access to it anyway. So, I am still seem to be stuck with this thing hanging out in memory.
By the way, excuse me, but I think I may have posted this question to the wrong discussion group since this has a bit of a web orientation, but perhaps it applies to workstation applications too.
|
|
|
|
|
If your code in Class1.GetInstance() is the same as per your first posting then the reference is being maintained by - Private Shared myInst As Class1 - which will persist as long as the appdomain (process, more or less) does.
Setting a reference to an instance of an object on the heap to nothing only clears that reference. As long as the number of references to a heap object is greater then zero the GC can't collect it.
If each request needs a new object I'm not sure why you are trying to use a singleton approach?
If you only want one per runtime then just call GetInstance() and don't worry about removing it.
If you do need to remove it once in a while, write a method like ...
Public Shared Sub ReleaseInstance()
myInst = Nothing
End Sub
... and call that.
------------------------------------------------
I'm largely language agnostic -
After a while they all bug me
------------------------------------------------
|
|
|
|
|
Thanks MidwestLimey, but that doesn't work either. Here is the class now:
Public Class Class1
Private Shared myInst As Class1
Private Shared myMutex As New System.Threading.Mutex
Public Shared myVal As Integer
Private Shadows disposed As Boolean
Public Shared Function GetInstance() As Class1
myMutex.WaitOne()
If myInst Is Nothing Then
myInst = New Class1
End If
myMutex.ReleaseMutex()
myInst.myVal += 1
Return myInst
End Function
Public Shared Sub ReleaseInstance()
myInst = Nothing
End Sub
End Class
Here is the calling code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myclass1 As Class1 = Class1.GetInstance
Response.Write(myclass1.myVal)
Class1.ReleaseInstance()
End Sub
Again, if I open this web page, it should kill the object, making any shared variables not accessible to another page that is opened. But, if I open another page, I will see "2" displayed, meaning that it incremented the value from the killed object. I can close all web pages, wait an hour, and if I start another page, I will then see the value "3" displayed. It just stays out there!
I am experimenting with this because I do want a single object in memory, which is to be shared among web pages, but I do want to be able to control when it is disposed of.
|
|
|
|
|
You never decrement myVal that I can see...
A good way to determine if instances are different is via object.GetHashCode()
------------------------------------------------
I'm largely language agnostic -
After a while they all bug me
------------------------------------------------
|
|
|
|
|
It is true that myVal is never decremented or set to Nothing. Does it need to be? It is a public shared variable within Class1. Shouldn't it be that if the Class1 instance is set to Nothing, then all variables within that class are automatically set to Nothing, even if they are shared?
|
|
|
|
|
Nope. It might help to think of shared fields/methods etc as existing in a separate class that is by default a singleton.
Shared fields exist on this singleton object that is created once and only once per appdomain (an appdomain is a subsection of a process - can be considered synonymous with process for most situations). This singleton object is referenced via the class name i.e. Class1.fieldY or Class1.methodX() and is available anywhere in the appdomain, accessors (public, friend etc) permitting.
Any values set will persist until the appdomain is unloaded. In this case myVal will continue to increase with every call to GetInstance() until IIS is restarted.
You can create and destroy as many Class1 instances as you wish, it will have no bearing on the shared fields defined in Class1.
To determine if the current instance of Class1 is the same as the last, call cls1.GetHashCode() where cls1 is an instance of Class1. If the values are different then you have different instances.
------------------------------------------------
I'm largely language agnostic -
After a while they all bug me
------------------------------------------------
|
|
|
|
|
Thanks for explaining that, MidwestLimey. I was not aware that those shared variables were independent of the class instance.
|
|
|
|
|
When you call GetInstance, you are getting a copy of the reference to the object. Clearing that copy does not clear the reference stored in the Shared variable.
What are you trying to accomplish, really? Shared variables are rarely useful in web applications.
---
single minded; short sighted; long gone;
|
|
|
|
|
Actually, I wasn't really trying to use the shared variable among the various web applications. Such variables are indeed quite useful, but for that, I would usually just use an Application variable. I was just using it here to see if my object was being destroyed or not. As it turns out, it wasn't the right way to figure that out.
What I was trying to do was gain a deeper understanding of the use of singleton objects in web applications.
|
|
|
|
|
Can ListItem be used in vb.net 2005?
When I use the code:
For Each item As ListItem in listbox2.Items<br />
If item.Value = fi.Name Then<br />
fFound = True<br />
End If
I will tell me to change ListItem to ListViewItem. When I change it I get the error:
Unable to cast object of type 'System.String' to type 'System.Windows.Forms.ListViewItem'.
Any suggestions?
jds1207
|
|
|
|
|
ListItem is a class in System.Web.UI.WebControls , it looks like your trying to use that in a windows form application.
jds1207 wrote: will tell me to change ListItem to ListViewItem. When I change it I get the error:
Unable to cast object of type 'System.String' to type 'System.Windows.Forms.ListViewItem
That will not work, you cant use a ListViewItem for a listBox
The ListBox.Items is an Object collection
For Each item As Object In listBox2.Items
If Convert.ToString(item) = fi.Name Then
fFound = True
End If
Next
|
|
|
|
|
i am trying to make an oledb connection with a password protected Access databaase.I tried the vizard on vb.net.but i got a connection error as " Cant start ur application because either Work group information file is missing or it is opened exclusievly by one another.please help me
|
|
|
|
|
Hi,
an example to connect to an Access database:
Dim sql As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _<br />
"Data Source=c:\resource.mdb;Jet OLEDB:System database=\\system.mdw;User Id=; Password=;"<br />
<br />
Using connection As New OleDb.OleDbConnection(sql)<br />
<br />
connection.ConnectionString = sql<br />
connection.Open()
System database is the path where you have Work group information and Data Source is the path where is your database.
Hope this help.
regards.
-- modified at 2:26 Wednesday 13th June, 2007
|
|
|
|
|
in my computer i use 2 ip address
i create a comuniction application using UDP and connect to server ( send and recive working good)
and now i whand to send data from the second ip address
how i can config to UdpClient to use the first ip or the second ?
Thanks
|
|
|
|
|
to send -
you can either randomize
you can use sequential - 1 then 2 then 1 then 2 etc
you can look at the PC's ip and if the last number is odd, use 1 else use 2
to receive -
you need to setup 2 listeners to handle both IPs
|
|
|
|
|
how i can select the localIp address
i use the UDPClient and i dont see where to insert my local ip
i need to send data from the first IPAddress and then send data from the second ipaddress
both send to the same ipaddress
|
|
|
|
|
Hi,
I'm using VB.NET 1.1.
I have a SqlDataReader varible that calls a function that has a return type of SqlDataReader like:
Dim dr As SqlDataReader = Me.GetProductsDataReader()
The function GetProductsDataReader() doesn't close the SqlDataReader any where, but then when I try to do (after the call):
While dr.Read()
' code here
End While
..then I get the following erro:
Invalid attempt to Read when reader is closed.
Please can some one help me?
Regards
ma se
|
|
|
|
|
Could you show your code in GetProductsDataReader() ?
|
|
|
|
|
Hi,
better you use
dim cmd1 As SqlCommand = conn.CreateCommand()<br />
Dim drd1 As SqlDataReader = cmd1.ExecuteReader()<br />
while drd1.read()<br />
..<br />
end while<br />
hope this would help.
regards
|
|
|
|