|
Hey,
Cheers again for the help, i have used a timer and made the AfterSelectEvent fire that. But will be changing my treenode to use a real dir structure soon, so i will keep that in mind thankyou.
Another question is that i am now using DSOFile to load MS Office file properties in to the form when the file node of my tree is double clicked.
This works and loads the file properties in to the form first time the node is double clicked, but if you try to go back to that file an error occurs saying that it cannot load the file properties because the file is open.
Is there anyway to close the file as soon as the properties have been retrieved?
Thank you for all your help
Chris
|
|
|
|
|
You can force the release of the underlying COM object by using Marshal.ReleaseComObject() on the instance of the DSO object you created. Try this:
Imports System.Runtime.Interop
.
.
.
' I'm assuming you're using the PropertyReadClass...
Dim dso As New DSOleFile.PropertyReaderClass
'
' Do whatever you need to with the object here...
'
' Now, release the unmanaged object and it's underlying resources.
Marshal.ReleaseComObject(dso)
' Drop our managed reference to the object.
dso = Nothing
.
.
.
And let the garbage collector do the rest...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hey,
Thanks for the reply. I have tried using the Marshal.ReleaseComObject but it does not seem to close the file, giving the error 'The file is open and cannot be read'. I have used hte import of InteropServices too.
my code is:
<br />
'DSO Properties<br />
Dim oDsoPropReader As DSOleFile.PropertyReader = New DSOleFile.PropertyReaderClass<br />
Dim oDsoFileProp As DSOleFile.DocumentProperties<br />
<br />
oDsoFileProp = oDsoPropReader.GetDocumentProperties(strFullPath) '<-- This line causes the error<br />
<br />
tbAuthor.Text = oDsoFileProp.Author<br />
tbFormat.Text = oDsoFileProp.AppName<br />
lblDateCreated.Text = oDsoFileProp.DateCreated<br />
lblDateModfied.Text = oDsoFileProp.DateLastSaved<br />
<br />
Marshal.ReleaseComObject(oDsoPropReader)<br />
<br />
oDsoFileProp = Nothing<br />
oDsoPropReader = Nothing<br />
Is my code wrong?, this help is really appreciated.
Chris
|
|
|
|
|
I have solved hte problem i also released the DocumentProperties as well as the reader, thanks for all your help Dave.
Chris
|
|
|
|
|
http://www.thecodeproject.com/vb/net/classinspector.asp[^]
This is a great little tool that can make implementing a snap.
There is a minor bug in the program that truncates some properties.
For instance, the Textbox property _PasswordChar has a default of Chr(0) which is a 'null.' The problem is that the textbox sees a null as an EOF and truncates the string. A simple solution is to remove the null char. To do this, change the line in showEnum and showControlProps from currentText = sb.ToString to read currentText = sb.ToString.Replace(Chr(0), "")
|
|
|
|
|
could anyone tell me why i've got this error message and how i can solve it?
thanks
Server Error in '/Log_In' Application.
--------------------------------------------------------------------------------
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 53: Loop
Line 54:
Line 55: DdlNoperiod.Items.AddRange(New Object() {"10", "11", "12", "13"})
Line 56:
Line 57: 'Put user code to initialize the page here
Source File: C:\Inetpub\wwwroot\Log_In\calendar.aspx.vb Line: 55
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
Log_In.calendar.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\Log_In\calendar.aspx.vb:55
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
|
|
|
|
|
DdlNoperiod.Items.AddRange(New Object() {"10", "11", "12", "13"})
I think DdlNoperiod is DropDownList. You can add only ListItem() to the DropDownList using AddRange method.
Do like this.
DdlNoperiod.Items.AddRange(New Object() {new ListItem("10"), new ListItem("11"), new ListItem("12"), new ListItem("13") })
|
|
|
|
|
unfortunately, it doesn't work by that way.
|
|
|
|
|
I have a function that I need to convert from C# to VB.
C#
public byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream)
{
int b1;
System.IO.MemoryStream tempStream = new System.IO.MemoryStream();
while((b1=theStream.ReadByte())!=-1)
{
tempStream.WriteByte(((byte)b1));
}
return tempStream.ToArray();
}
My VB So far...
Public Function ConvertStreamToByteBuffer(ByVal theStream As System.IO.Stream) As Byte()
Dim b1 As Integer
Dim tempStream As New System.IO.MemoryStream
While ((b1 = theStream.ReadByte()) <> -1)
tempStream.WriteByte(((byte)b1))
End While
Return tempStream.ToArray()
End Function
i keep getting an error of: 'Byte' is a type, and so is not a valid expression. referring to the code in the while statement.
Please can someone help me to convert the function
Thank You
|
|
|
|
|
You have only one error in the line tempStream.WriteByte(((byte)b1)) . The VB equivelent of (byte)b1 is CType(b1, Byte) .
The full VB code should be
Public Function ConvertStreamToByteBuffer(ByVal theStream As System.IO.Stream) As Byte()
Dim b1 As Integer
Dim tempStream As New System.IO.MemoryStream
While Not ((b1 = theStream.ReadByte) = -1)
tempStream.WriteByte(CType(b1, Byte))
End While
Return tempStream.ToArray
End Function
|
|
|
|
|
here is a pretty cool site that converts vb to c# and vica versa - its not perfect it sure beats typing everything out -
http://www.developerfusion.com/utilities/convertvbtocsharp.aspx
|
|
|
|
|
Personaly I use SharpDevelop[^] which has a built in C# to VB.Net and VB.Net to c# converter. I use it a lot as I write in VB.Net as work and C# at home. It is quicker to convert whole classes than to rewrite from scratch, even though the conversion is only 99% perfect.
|
|
|
|
|
Note that this function is not very efficient. Why is b1 an integer to begin with? And as for reading a single byte at a time...
my blog
|
|
|
|
|
Hi, I want to display the data from Ms access database (ex: Northwind.mdb) to a DataGrid control in VB.Net by using the code only. I don't want to bind the datagrid to any data control. Is it possible to do that? If it is possible can any one give me some sample code to work with it? Now I learn how to bind the data grid with Data Adapter configuration wizard, but i think it is not flexible like the code.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
This should get you on the right track. Personally I like using the wizards but I use my own commands with the adapters and datasets that the wizard creates. This code works but don't like how it displays data in the datagrid. Maybe you can work it out. Enjoy
Dim oCmd As New OleDb.OleDbCommand()
Dim oDA As New OleDb.OleDbDataAdapter(oCmd)
Dim oDS As New DataSet()
Dim strCommand As String
Dim oConn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Northwind.mdb;Mode=ReadWrite; Persist Security Info=False")
strCommand = "SELECT * FROM <table name>"
Try
oConn.Open()
With oCmd
.CommandType = CommandType.Text
.Connection = oConn
.CommandText = strCommand
End With
Catch ex As Exception
MessageBox.Show("Failed to connect to data source")
Finally
oConn.Close()
End Try
oDS.Clear()
oDA.Fill(oDS)
DataGrid1.DataSource = oDS Let me know if you can't get this to work. Remember to use your own connection path and in the command string use the table name you are selecting from.
|
|
|
|
|
Dear Britnt7, Thank you very much for your sample code. Now it is working and I will learn to customize it as much as I can. But I have one more question. I put your give that give to me on the form load, and the data fill in the datagrid as I want but the grid is not display until I click on the plug sign (+) then it display the data as I want. Do you know how to ignore this plus sign? I mean when the form load with your code I can see the data display directly in the datagrid without click the plus sign to see the data in the grid. Thank you very much for your help!!!
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
Dear Britnt7, I have one more question. In VB6 when I transfer the data from database to list view control, I have an opportunity to give the name of the column header to a difference name from the field of the table in database but I can use do while ... loop to put the data one by one in the list view. But the datagrid in VB.net seem that have no opportunity to code to change the name of the column, is it true? The reason is the database that I design is written in my own language. The field of the table written in English while the record is written in my own language. So when I display on the grid it display in english only so the column header could read in english but the record could not read. But when I change the font to my language the record could read (know the meaning) but the column header could not read. Any possible solution?
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
Hi..
Can anybosy telll me a gud site or a tutorial to know about web class libraries.I have a couple of pages that are common to quite a number of applications.
So would like to add them into a library storing at one places and calling them from various applications.Is it possible??
Thanks in anticipation
g
|
|
|
|
|
Hello,I have the following project and I have tried and tried but can't seem to get it. Can anyone help?
I have to write a program to campare the secant method with newton's method for finding the roots of each function:
x^3 - 3x + 1 with starting point Xo=2
x^3 - 2 sin x with starting point Xo=.5
The instructions also state to use the X1 value from Newton's method as the second starting point for the secant method and to print out each iteration for both methods. I appreciate any help.
|
|
|
|
|
L_JIMENEZ wrote:
I have tried and tried
What have you tried ? Where are you having trouble ?
L_JIMENEZ wrote:
I appreciate any help.
Sure, but no-one is going to do your homework for you. If you can post what you've got, and where you're stuck, we're all glad to help out.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
the purpose of this code is to display data in specific textboxes when a user click on any items in listbox ... this one i'm coding for web application.
but actually, it doesn't work at all ... i could not figure out the problems ...
could anyone there help me please?
thanks in advance
Private Sub activateform()
Dim mlstoneDreader As OleDb.OleDbDataReader
Dim mlstoneCommand As OleDb.OleDbCommand
Dim slect As String
Dim StSQl As String
Dim ConnStr As String
ConnStr = BuildSQLConnection()
slect = lstmilestone.SelectedItem.Value
StSQl = "Select staffId, LastName, FirstName, Email "
StSQl &= " From Staff "
StSQl &= " where staffId = " & slect
Try
mlstoneCommand = New OleDb.OleDbCommand()
With mlstoneCommand
.Connection = New OleDb.OleDbConnection(ConnStr)
.Connection.Open()
.CommandText = StSQl
mlstoneDreader = .ExecuteReader(CommandBehavior.SingleRow)
End With
If mlstoneDreader.Read() Then
With mlstoneDreader
txtid.Text = .Item("StaffId").ToString()
txtmlname.Text = .Item("LastName").ToString()
txtdesc.Text = .Item("FirstName").ToString()
End With
Else
ClearAll()
End If
mlstoneDreader.Close()
mlstoneCommand.Connection.Close()
Catch mlstone_e As Exception
MsgBox("Connection failed")
End Try
End Sub
Private Sub ClearAll()
txtid.Text = " "
txtmlname.Text = " "
txtdesc.Text = " "
txtnoofday.Text = " "
End Sub
|
|
|
|
|
Fired Dragon wrote:
but actually, it doesn't work at all ... i could not figure out the problems ...
Why not ? i.e. what doesn't it do ? Have you traced through to see what is going into your SQL ? Run your SQL in query analyser to make sure it should return the values you expect ? etc.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
hi christ
although, data displays in a listbox, when i select items in the listbox, it doesn't display in the textboxes.
i've ran my sql in query analyser, the results show out correctly.
could you help me to solve out please?
|
|
|
|
|
You say it's a web application - when you click on an item in the listbox, does it postback ? Have you put breakpoints in to verify that your code is being called ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Public Class milestone
Inherits System.Web.UI.Page
Protected WithEvents btnadd As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents btnmodify As System.Web.UI.WebControls.Button
Protected WithEvents Btndelete As System.Web.UI.WebControls.Button
Protected WithEvents txtmlname As System.Web.UI.WebControls.TextBox
Protected WithEvents txtnoofday As System.Web.UI.WebControls.TextBox
Protected WithEvents lstmilestone As System.Web.UI.WebControls.ListBox
Protected WithEvents txtid As System.Web.UI.WebControls.TextBox
Protected WithEvents txtdesc As System.Web.UI.WebControls.TextBox
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InitializeComponent()
Listmilestone()
'Put user code to initialize the page here
End Sub
Private Function Listmilestone()
Dim mlstoneDreader As OleDb.OleDbDataReader
Dim mlstoneCommand As OleDb.OleDbCommand
Dim slect As Web.UI.WebControls.ListBox
Dim StSQl As String
Dim ConnStr As String
ConnStr = BuildSQLConnection()
StSQl = " Select staffId, FirstName "
StSQl &= " From staff"
mlstoneCommand = New OleDb.OleDbCommand()
With mlstoneCommand
.Connection = New OleDb.OleDbConnection(ConnStr)
.Connection.Open()
.CommandText = StSQl
mlstoneDreader = .ExecuteReader(CommandBehavior.SequentialAccess)
End With
lstmilestone.Items.Clear()
Do While mlstoneDreader.Read()
lstmilestone.Items.Add(mlstoneDreader.Item("Firstname"))
Loop
mlstoneDreader.Close()
If lstmilestone.Items.Count > 0 Then
lstmilestone.SelectedIndex = 0
End If
mlstoneDreader.Close()
mlstoneCommand.Connection.Close()
End Function
Private Sub lstmilestone_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstmilestone.SelectedIndexChanged
activateform()
End Sub
Private Sub activateform()
Dim mlstoneDreader As OleDb.OleDbDataReader
Dim mlstoneCommand As OleDb.OleDbCommand
Dim slect As String
Dim StSQl As String
Dim ConnStr As String
ConnStr = BuildSQLConnection()
slect = lstmilestone.SelectedItem.Value
StSQl = "Select staffId, LastName, FirstName, Email "
StSQl &= " From Staff "
StSQl &= " where staffId = " & slect
Try
mlstoneCommand = New OleDb.OleDbCommand()
With mlstoneCommand
.Connection = New OleDb.OleDbConnection(ConnStr)
.Connection.Open()
.CommandText = StSQl
mlstoneDreader = .ExecuteReader(CommandBehavior.SingleRow)
End With
If mlstoneDreader.Read() Then
With mlstoneDreader
txtid.Text = .Item("StaffId").ToString()
txtmlname.Text = .Item("LastName").ToString()
txtdesc.Text = .Item("FirstName").ToString()
End With
Else
ClearAll()
End If
mlstoneDreader.Close()
mlstoneCommand.Connection.Close()
Catch mlstone_e As Exception
MsgBox("Connection failed")
End Try
End Sub
Private Sub ClearAll()
txtid.Text = " "
txtmlname.Text = " "
txtdesc.Text = " "
txtnoofday.Text = " "
End Sub
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
milestoneAdd()
End Sub
Private Sub milestoneAdd()
Dim stSQL As String
Dim mlstoneCommand As OleDb.OleDbCommand
Dim milestone_Rows As Integer
Dim SQLConn As New Clsconnection()
stSQL = "INSERT INTO ProjectMilestone "
stSQL &= " Id, "
stSQL &= " Description, "
Try
mlstoneCommand = New OleDb.OleDbCommand()
With mlstoneCommand
.Connection = New OleDb.OleDbConnection(BuildSQLConnection())
.Connection.Open()
.CommandText = stSQL
milestone_Rows = .ExecuteNonQuery()
If milestone_Rows <> 1 Then
MsgBox("Did not insert row")
End If
.Connection.Close()
End With
Catch oException As Exception
MsgBox(oException.Message)
End Try
End Sub
Private Function BuildSQLConnection() As String
Dim ConnStr As String
ConnStr = "Provider=sqloledb"
ConnStr &= ";Data Source=(local)"
ConnStr &= ";Initial Catalog=PROMAN"
ConnStr &= ";User ID=sa"
ConnStr &= ";Password=hien"
Return ConnStr
End Function
End Class
|
|
|
|