Copy a pdf file from a local directory to my sql database.
(Friday, January 20, 2006)
Found the following interesting discussion in the Newsgroups:
Copy a pdf file from a local directory to my sql database. by:elaine.chua@epcos-dot-com.no-spam.invalid (argeam)
| Hi, i'm doing a project on generating a crystalreport and viewing it in a pdf format. I'm using vb.net and sql server.
i managed to general the crystalreport, save it in local directory then view it. but on the other hand i would also like to save the pdf file into my sql database. this is the difficult part and also the part which i'm stuck now. follows are all my code. hope there will be someone who can help me! thanks!
Dim myConnection As New SqlClient.SqlConnection() myConnection.ConnectionString = Dim MyCommand As New SqlClient.SqlCommand() MyCommand.Connection = myConnection Dim CommandStr As String
CommandStr = "execute usp_rpt_note @note_id= '" & Label_NoteID.Text & "'" MyCommand.CommandText = CommandStr MyCommand.CommandType = CommandType.Text Dim MyDA As New SqlClient.SqlDataAdapter() MyDA.SelectCommand = MyCommand Dim myDS As New Note_DataSet()
MyDA.Fill(myDS, "usp_rpt_note") Dim oRpt As New Note_CrystalReport1() oRpt.SetDataSource(myDS)
oRpt.ResourceName = "Note_CrystalReport1.rpt"
Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions() oRpt.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile oRpt.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat
Dim filename, filenamepdf, filenamexls As String filename = UCase(Logon_Name(Request.ServerVariables("LOGON_user"))) & CStr(Year(Now())) & CStr(Month(Now())) & CStr(Day(Now())) & CStr(Hour(Now())) & CStr(Minute(Now())) & CStr(Second(Now())) & CStr(CInt(Int((100000 * Rnd(200)) + 1))) filename = filename
filenamepdf = "D:\Inetpub\wwwroot\report\temp\" & filename & ".pdf"
DiskOpts.DiskFileName = filenamepdf
oRpt.ExportOptions.DestinationOptions = DiskOpts oRpt.Export()
' Database operation variables Dim connect As New SqlClient.SqlConnection("Initial Catalog=st;Data Source=localhost;Integrated Security=SSPI;Persist Security Info=True;") Dim cmd As New SqlClient.SqlCommand("usp_copy_frm_directory", connect) Dim p As SqlClient.SqlParameter Dim uploaded_file As String Dim strFileUpload As String
'uploaded_file = Request.QueryString("strFileName") strFileUpload = "d:\Inetpub\wwwroot\report\temp\" & filename & ".pdf" filename = strFileUpload
'File/data variables Dim imageStream As New IO.FileStream(filename, IO.FileMode.Open)
'Dim imagestream As New IO.FileStream(Server.MapPath("ToBeUpload.doc"), IO.FileMode.Open) Dim imageData(imageStream.Length) As Byte Dim FileSize As Integer = CType(imageStream.Length, Integer) Dim UploadDate As DateTime = DateTime.Now 'Dim sContentType As String = imageStream.GetType.ToString 'File1.PostedFile.ContentType Dim sContentType As String = "Application/pdf" 'Dim sContentType As System.IO.Stream = File1.PostedFile.InputStream ' Read the image data and close the stream imageStream.Read(imageData, 0, imageStream.Length) imageStream.Close()
' Save the image cmd.CommandType = CommandType.StoredProcedure
p = New SqlClient.SqlParameter("@ImageData", SqlDbType.Image) p.Value = imageData cmd.Parameters.Add(p)
p = New SqlClient.SqlParameter("@ContentType", SqlDbType.NVarChar) p.Value = sContentType cmd.Parameters.Add(p)
connect.Open()
cmd.ExecuteNonQuery() connect.Close()
cmd.Dispose() connect.Dispose()
Dim strPDF As String strPDF = "./temp/" & filename & ".pdf" Response.Redirect(strPDF)
Somehow it didnt work! i'm calling the above codes as a function in my pageload.
Hope help is given! thanks!!
| | | Reply: by:Anonymous
| | | Well, from what I can see from a quick review of the code is that you are attempting to store the image as an Image in the database. I have never gotten that to work. I would take the memorystream that you have, get the byte array from the buffer and store that in the database (the byte array) as a BLOB. That why you are not depnedant on the datastructure requirements of the SqlType.Image.
HTH -- David Williams
|
Posted by Xander Zelders
File Handling, XML
Found the following interesting discussion in the Newsgroups:
File Handling, XML by:Martin
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <META content="MSHTML 6.00.2800.1106" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face=Tahoma size=2>Dear All VB.NET programmers,</FONT></DIV> <DIV><FONT face=Tahoma size=2></FONT> </DIV> <DIV><FONT face=Tahoma size=2>Does anyone of you have a good article reference to learn file handling (text, binary, etc) and XML (creating, reading, etc) in VB.NET.</FONT></DIV> <DIV><FONT face=Tahoma size=2></FONT> </DIV> <DIV><FONT face=Tahoma size=2>I heard that XML file may act like database and it can be created using one of ADO.NET component. Is it true ?</FONT></DIV> <DIV><FONT face=Tahoma size=2></FONT> </DIV> <DIV><FONT face=Tahoma size=2>Thx Alot ...</FONT></DIV> <DIV><FONT face=Tahoma size=2></FONT> </DIV> <DIV><FONT face=Tahoma size=2>MARTIN</FONT></DIV> <DIV><FONT face=Tahoma size=2>-NEWBIE IN VB.NET-</FONT></DIV></BODY></HTML>
| | | Reply: by:One Handed Man \( OHM - Terry Burns \)
| | | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <META content="MSHTML 6.00.2800.1400" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face=Arial size=2>The DataSet class is one an example of how you can persist your Data. Check out the ReadXML and WriteXML member functions of the DataSet Class.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>HTH</FONT></DIV> <DIV><BR>-- <BR><BR>OHM ( Terry Burns )<BR> . . . One-Handed-Man . . .. </DIV> <DIV> </DIV> <DIV>Time flies when you don't know what you're doing<BR></DIV> <BLOCKQUOTE dir=ltr style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px"> <DIV>"Martin" <<A href="mailto:martin.panggabean@jusufind.com">martin.panggabean@jusufind..com</A>> wrote in message <A href="news:u3kot8$XEHA.3988@tk2msftngp13.phx.gbl">news:u3kot8$XEHA.3988@tk2msftngp13.phx.gbl</A>...</DIV> <DIV><FONT face=Tahoma size=2>Dear All VB.NET programmers,</FONT></DIV> <DIV><FONT face=Tahoma size=2></FONT> </DIV> <DIV><FONT face=Tahoma size=2>Does anyone of you have a good article reference to learn file handling (text, binary, etc) and XML (creating, reading, etc) in VB.NET.</FONT></DIV> <DIV><FONT face=Tahoma size=2></FONT> </DIV> <DIV><FONT face=Tahoma size=2>I heard that XML file may act like database and it can be created using one of ADO.NET component. Is it true ?</FONT></DIV> <DIV><FONT face=Tahoma size=2></FONT> </DIV> <DIV><FONT face=Tahoma size=2>Thx Alot ...</FONT></DIV> <DIV><FONT face=Tahoma size=2></FONT> </DIV> <DIV><FONT face=Tahoma size=2>MARTIN</FONT></DIV> <DIV><FONT face=Tahoma size=2>-NEWBIE IN VB.NET-</FONT></DIV></BLOCKQUOTE></BODY></HTML>
| | | Reply: by:rawCoder
| | | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <META content="MSHTML 6.00.2800.1400" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face=Arial size=2>Hi Martin,</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> i currently dont know any articels but</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> i have used this cool thing - using XML as a DataStore.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> Just to get started this is what you have to do.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> Right Click the project and Add New Item. Select DataSet name it and Add it in your project.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> You will be given this DataSet1.xsd design view.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> Here you can add an element which will act as a table.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> You can now use this dataset as any normal dataset.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> To really see the XML part, you can try WriteXML and ReadXML methods along with WriteXMlSchema and ReadXMLSchema methods on the dataset.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> Infact I think you can even use any 'Database Connected dataSet' to read/write XML data and the Schema to/from file.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> I encourage you to look into the xsd in the design view and xml view and the accompanying xml files to see what actually happens.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>Hope it helps,</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>Thank You,</FONT></DIV> <DIV><FONT face=Arial size=2>rawCoder</FONT></DIV> <BLOCKQUOTE dir=ltr style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px"> <DIV>"Martin" <<A href="mailto:martin.panggabean@jusufind.com">martin.panggabean@jusufind..com</A>> wrote in message <A href="news:u3kot8$XEHA.3988@tk2msftngp13.phx.gbl">news:u3kot8$XEHA.3988@tk2msftngp13.phx.gbl</A>...</DIV> <DIV><FONT face=Tahoma size=2>Dear All VB.NET programmers,</FONT></DIV> <DIV><FONT face=Tahoma size=2></FONT> </DIV> <DIV><FONT face=Tahoma size=2>Does anyone of you have a good article reference to learn file handling (text, binary, etc) and XML (creating, reading, etc) in VB.NET.</FONT></DIV> <DIV><FONT face=Tahoma size=2></FONT> </DIV> <DIV><FONT face=Tahoma size=2>I heard that XML file may act like database and it can be created using one of ADO.NET component. Is it true ?</FONT></DIV> <DIV><FONT face=Tahoma size=2></FONT> </DIV> <DIV><FONT face=Tahoma size=2>Thx Alot ...</FONT></DIV> <DIV><FONT face=Tahoma size=2></FONT> </DIV> <DIV><FONT face=Tahoma size=2>MARTIN</FONT></DIV> <DIV><FONT face=Tahoma size=2>-NEWBIE IN VB.NET-</FONT></DIV></BLOCKQUOTE></BODY></HTML>
|
Posted by Xander Zelders
Refresh Part of Client Area
Found the following interesting discussion in the Newsgroups:
Refresh Part of Client Area by:Anonymous
| I know that Invalidate allows you to invalidate only part of the client area and Refresh allows you to force the entire client area to update right now, but is there any way to force part of the client area (e.g., only the invalidated regions) to update right now (without using DoEvents)?
Thanks, Lance
| | | Reply: by:Richard Myers
| | | Hi Lance
Invalidate is an overloaded method. You can pass a region/rectangle parameter to the method which will allow you to do as you wish.
hth Richard
| | | Reply: by:Anonymous
| | | Yes, I am familiar with the overloaded Invalidate methods. But, what I want to do is to force only part of the client area to update immediately. Using Invalidate allows you to specify which region(s) of the client area that you want to update, but the update does not happen immediately. Using Refresh causes the client area to update immediately, but you can not limit the update to a specified region.
Any other ideas?
Thanks again, Lance
| | | Reply: by:Richard Myers
| | | Hi Lance, Control.Invalidate(region) Control.Update() Causes the control to redraw the invalidated regions within its client area by executes any pending requests for painting.
Richard
| | | Reply: by:Anonymous
| | | Wonderful! Thanks a lot.
|
Posted by Xander Zelders
Fail To reset the combobox.text
Found the following interesting discussion in the Newsgroups:
Fail To reset the combobox.text by:Agnes
| My code is so simple to reset the text or set text to blank after the user choose the value in combobox.
Private Sub cboBLData_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboBLData.SelectedIndexChanged Select Case UCase(Me.cboBLData.Text) Case "CNTR&MARKING" Dim frmCntrMark As New frmSeaCntrMarking() frmCntrMark.pHBLNo = Me.txtHBLNo.Text frmCntrMark.ShowDialog()
End Select -> Me.cboBLData.ResetText() -> Me.cboBLData.Text = "" Both code are file to set the blank text.
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
Try to set the 'SelectedIndex' to -1 twice.
-- Herfried K. Wagner
| | | Reply: by:Anonymous
| | | What's the DropDownStyle Property set to?
-- Erik Porter
|
Posted by Xander Zelders
.NET 1.1 SP1 Change list
Found the following interesting discussion in the Newsgroups:
.NET 1.1 SP1 Change list by:Brian Henry
| Does anyone know where the change / bug fix list for .NET 1.1 SP1 is? it'd be nice to know what fixes will be in when it's release later this year, thanks!
| | | Reply: by:Jochen Kalmbach
| | | Brian Henry wrote:
Here is a list of all changes: http://msdn.microsoft.com/netframework/downloads/updates/sptechpreview/cont ent11sp1.aspx -- Greetings Jochen
Do you need a memory-leak finder ? http://www.codeproject.com/tools/leakfinder.asp
Do you need daily reports from your server ? http://sourceforge.net/projects/srvreport/
|
Posted by Xander Zelders
Treenode.clone method
Found the following interesting discussion in the Newsgroups:
treenode.clone method by:bclegg
| Hi, When I implement the example code it errors with 'No parameterless constructor defined for this object.'
experimenting with dim o as object = mytreenode.clone() gives the same error.
The example code is: Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim lastNode As TreeNode lastNode = tvAvailable.Nodes(tvAvailable.Nodes.Count - 1). _ Nodes(tvAvailable.Nodes(tvAvailable.Nodes.Count - 1).Nodes.Count - 1)
' Clone the last child node. Dim clonedNode As TreeNode = CType(lastNode.Clone(), TreeNode)******Error HERE**************
' Insert the cloned node as the first root node. tvAvailable.Nodes.Insert(0, clonedNode) MessageBox.Show(lastNode.Text & _ " tree node cloned and added to " & tvAvailable.Nodes(0).Text)
End Sub
Is this method flawed? Does anybody have working code for copying a treenode from one tree to another? Thanks Bob -- Please take out the garbage before using reply address.
| | | Reply: by:v-phuang@online.microsoft.com (Peter Huang)
| | | Hi Bob,
I can not reproduce the problem with the code below. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For i As Integer = 0 To 7 Me.TreeView1.Nodes.Add("Hello" + i.ToString()) Next Me.TreeView1.Nodes(7).Nodes.Add("Test") End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim lastNode As TreeNode lastNode = TreeView1.Nodes(TreeView1.Nodes.Count - 1).Nodes(TreeView1.Nodes(TreeView1.Nodes.Count - 1).Nodes.Count - 1) ' Clone the last child node. Dim clonedNode As TreeNode = CType(lastNode.Clone(), TreeNode) ' Insert the cloned node as the first root node. TreeView1.Nodes.Insert(0, clonedNode) MessageBox.Show(lastNode.Text & _ " tree node cloned and added to " & TreeView1.Nodes(0).Text) End Sub
Also you may try to check if you have another class named TreeNode. I think you may try to declare the TreeNode as below System.Windows.Forms.TreeNode instead of TreeNode. Best regards,
Peter Huang Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.
| | | Reply: by:bclegg
| | | Hi Peter, Problem solved. Your code pointed the way. My tree view had a root node which was a derived class and had no parameterless constructor. Thanks Bob Peter Huang wrote: -- Please take out the garbage before using reply address.
|
Posted by Xander Zelders
Web site URL -> thumbnails/printscreen
Found the following interesting discussion in the Newsgroups:
Web site URL -> thumbnails/printscreen by:JD
| I need to create a thumbnail/printscreen (picture - gif or jpeg) of the existing website on the internet. I am able to "grab" the content of other website, but how do I create a picture from it (all I have is HTML)?
I provide URL and it returns picture (printscreen) of the website. I even don't know where to start.
Explanation: I need it for website where people nominate websites in certain categories and people vote for them. In the past I created thumbnails manually and stored them with other data in DB. But it is getting too much and I would like somehow automate it. Any other 3rd party solutions (free are preferred :-)) are also welcomed. Thanks JD
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
<URL:http://sourceforge.net/projects/iecapt/>
-- Herfried K. Wagner
| | | Reply: by:Ken Cox [Microsoft MVP]
| | | You might want to try SnagIt. It captures Web pages to an image. They have a free trial version.
http://www.techsmith.com/products/snagit/default.asp
captures from today's most advanced Web pages. Now - capture thumbnail images as well as the larger images that appear behind them, collect images from complex query strings within URLs, and block pop-ups that may occur as a result of going outside the current domain while searching for images."
|
Posted by Xander Zelders
How to get app build for display on main form?
Found the following interesting discussion in the Newsgroups:
How to get app build for display on main form? by:Jeremy
| Can't seem to find current build number anywhere at runtime. Application.productversion gives me a build number-like string that has no relation to anything I know about.
Jeremy
| | | Reply: by:Greg Burns
| | | That would be it. It is not what most expect to see. It is based on a timestamp.
If you want to see 1.0.0.1 or something, you'll have to manually increment it yourself in the the AssemblyInfo.vb file.
Greg
| | | Reply: by:Jeremy
| | | Greg, thanks. But what about the version# that is in the setup project, is that not available as a property?
Jeremy
| | | Reply: by:Greg Burns
| | | Not sure. I think that version number is purely to version the installer code itself.
Setup projects are not my forte. I just use XCOPY. :^)
Greg
|
Posted by Xander Zelders
Multiple Form Issue - Closing Forms
Found the following interesting discussion in the Newsgroups:
Multiple Form Issue - Closing Forms by:Keith
| Moving from form to form seems straight forward - but how would one go about closing a form FROM another form?
I use me.close - to close out a form and the following to open ("jump to") a new form: dim f2 as new form2 form2.showdialog() How would one go about closing a form - FROM - another form? In other words closing form 1 - FROM - form2
Thank you.
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
<URL:http://www.google.de/groups?selm=u%23xQOutWDHA.2100%40TK2MSFTNGP11.phx.gbl>
-- Herfried K. Wagner
| | | Reply: by:
| | | Thank you for the post reply - but that does not answer my question. This code reference - will close form1 and open form2. I know how to do that.
I'm saying - if one had 3 forms. 1, 2, and 3 - 1 has a button that opens 2 but leaves 1 open. 2 has a button that opens 3 and leaves 2 open. Let's say I want to close form 1 or 2 - FROM form 3 - how would I do that. Every time I attempt to write some code to close form1 or form2 - I get an "An unhandled exception of type 'System.NullReferenceException'"
|
Posted by Xander Zelders
Datetime to date & time & back
Found the following interesting discussion in the Newsgroups:
Datetime to date & time & back by:John
| Hi
I am using and access datetime field to store both date & time. How can I split it into date & time after reading the field and then combine the date & time back into datetime when storing it?
Thanks
Regards
| | | Reply: by:Cor Ligthert
| | | Hi John,
You have placed an almost the same message later, please keep it with one post, with this people take time and after a while are not answering you anymore because they see it it useless.
Cor
|
Posted by Xander Zelders
Referencing properties of objects wthin object Collections
Found the following interesting discussion in the Newsgroups:
referencing properties of objects wthin object Collections by:Terry
| What is the syntax for referencing the properties of objects within Collections of objects?
EXAMPLE:
Dim MCoil As New Coil MCoil = CoilCollection("3456") TextBox1.Text() = MCoil.CoilDesc
WANT TO BE ABLE TO AVOID INTERMEDIARY COPY (SOEMTHING LIKE):
TextBox1.Text() = CoilCollection("3456").CoilDesc
Thanks, Terry
| | | Reply: by:Ken Tucker [MVP]
| | | Hi,
TextBox1.Text() = DirectCast(CoilCollection("3456"),Coil).CoilDesc
Ken
| | | Reply: by:Cablewizard
| | | Since you mention Collections of Objects, so I am assuming you are not using a strongly typed collection. I am also assuming that your problem is that the Object returned, does not know about the CoilDesc property. In this case, you seem fairly certain that the returned Object will be of type Coil, so I would recommend a DirectCast. TextBox1.Text = DirectCast(CoilCollection("3456"), Coil).CoilDesc
In a nutshell, it is doing the same thing you were doing before, but just in 1 line and a little quicker. (note, I didn't test the above, so please forgive any typo's)
Gerald
|
Posted by Xander Zelders
Is it possible and how to do it ;)
Found the following interesting discussion in the Newsgroups:
Is it possible and how to do it ;) by:Anonymous
| Hello I would like to add a new control ( blend panel ) to my application, but there for example 10 controls existing already on the form1 and when I put panel on it and set docking to fill... you know what happen I see only panel ;) Is there any simple way to transfer all this controls from form1 onto blend-panel ? Student
| | | Reply: by:Greg Burns
| | | I assume you mean at design time, not run-time.
Select controls -> Edit Cut. Click on Panel. Paste. You were will most likely have to reattach event handlers (if you had any defined).
Greg
news:44C6AD14-C274-4B37-BBB2-772E9A21C4B3@microsoft.com...
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
Select all controls, press Ctrl+X (or "Cut" from the context menu), add the panel, select it and press Ctrl+V (or "Paste" from the context menu).
-- Herfried K. Wagner
|
Posted by Xander Zelders
How to cache my dataset?
Found the following interesting discussion in the Newsgroups:
Caching my dataset by:Anonymous
| Hi, I have a desktop app written in vb.net. It takes a wile to load from sql server via a stored proc. Is there a way I can cache the dataset so that If i reopen the the program it loads faster. The data in the database doesn't change that often. Where can I find info on this?
Thanks
| | | Reply: by:William Ryan eMVP
| | | The first thing I'd determine is why is it taking so long and try to address that issue. However that's obviously not your question. Anyway, you can use dataSet.WriteXML to serialize it locally, just specify a local path. Then when your app starts, check for the existence of the file and use ReadXML if it does. All you need to do is pass in the path/file at a minimum although specifying schema will speed things up dramatically. One warning though, if you have a lot of data ie >1000 records, this is probably not going to be the fastest thing in the world either depending on teh schema of the dataset.
-- W.G. Ryan
Is there a way I can cache the dataset so that If i reopen the the program it loads faster. The data in the database doesn't change that often. Where can I find info on this?
| | | Reply: by:Anonymous
| | | Thanks for the response. The reason my sp is taking that long is that I am quering a progress database frpm sql server via openquery to get data. The result is less that 30 rows. What do mean by "specifying schema will speed things up dramatically"?
Thanks
|
Posted by Xander Zelders
Interop Issue
Found the following interesting discussion in the Newsgroups:
Interop Issue by:Anonymous
| All,
I have an app that has the call some functions in a DLL Written in C. The function I am having problems with has a parameter
char FAR * lpsvValue
After looking on MSN I set up my declare statement to use the parameter
ByVal Value As String
In my declerations I declare the variable that I am going to pass in as follows:
Dim sInstanceName As String sInstanceName = New String(CChar(" "), 128)
My function call works fine and I get back the value that I want. The problem I have is I can't work on the value. Specifically, I need to concatentate this string value with another string. I have tried using the concat method, the string builder, and even the good old & symbol. No matter what, all I get is the value that the function returned. The program acts like the piece I am trying to append doesn't even exist.
The only way I have been able to work around it is by assigning the value returned to a text box control and then taking that value and appending the additional string to it. However, that seems a but cumbersome and limiting.
What am I missing? What is the text box doing that enables it to get the value out of that string?
Any thoughts would be appreciated. Thanks!
| | | Reply: by:Klaus H. Probst
| | | Try passing a StringBuilder instance instead.
You'll probably have to modify the declaration, but String and StringBuilder are interchangeable there; just make sure you do initialize the SB to 128 chars or whatever buffer size you need.
Always use StringBuilder if you're passing non-const string buffers to APIs via interop.
-- Klaus H. Probst function I am having problems with has a parameter follows: problem I have is I can't work on the value. Specifically, I need to concatentate this string value with another string. I have tried using the concat method, the string builder, and even the good old & symbol. No matter what, all I get is the value that the function returned. The program acts like the piece I am trying to append doesn't even exist. returned to a text box control and then taking that value and appending the additional string to it. However, that seems a but cumbersome and limiting. value out of that string?
|
Posted by Xander Zelders
How to place a value in one text box to a text box on another form?
Found the following interesting discussion in the Newsgroups:
Placing a value in one text box to a text box on another form. by:Anonymous
| I have a pop-up text box that allows the users to modify values in a text box. Once they click on the "OK" button the pop-up form will close, and I want the main form to have the fields they edited on the pop-up form to reflect the changes.
Such as on the main form the Create Date = 7/2/2004. On the pop-up form they can edit the Create Date. If they edit the Create Date on the pop-up form to say 7/4/2004, and then click "OK". I would like for the pop-up form to close and the Create Date on the main form be equal to 7/4/2004, due to the edits.
Sorry if this seems to elementary, I am new with VB.Net and trying to learn as I program along. Thank you for your time.
T.J.
| | | Reply: by:Rob T
| | | You'll have to use Javascript to do it.
something like this: window.opener.document.forms['Fom1'].elements['ToCell'].value = 'FromCell'
I believe it's somewhere on www.javascript.com. Hopefully that will get you pointed in the right direction. news:B2022D4B-9EDA-44B9-B0B1-C64AC350E83F@microsoft.com... box. Once they click on the "OK" button the pop-up form will close, and I want the main form to have the fields they edited on the pop-up form to reflect the changes. they can edit the Create Date. If they edit the Create Date on the pop-up form to say 7/4/2004, and then click "OK". I would like for the pop-up form to close and the Create Date on the main form be equal to 7/4/2004, due to the edits. learn as I program along. Thank you for your time.
| | | Reply: by:Anonymous
| | | Straight VB.NET Declare the popup in the main form example public frmMyPop as new NameOfMyPopForm(me)
in popform declare a name as form (intellisence will allow you to select the name of your main form) example Public MFRM as MDI
then in the Public Sub New() add a variable to receive the "ME" from the main form and set the local reference to the main form to the parameter received - you may need to open the #REGION area to see the NEW sub
example Public Sub New(ByVal frmMDI As MDI) MyBase.New()
'This call is required by the Windows Form Designer. InitializeComponent()
'Add any initialization after the InitializeComponent() call MFRM = frmMDI End Sub
you may then reference most anything in MFRM like this MFRM.Textbox1.text = me.textbox1.text etc.
|
Posted by Xander Zelders
DialUp Networking
Found the following interesting discussion in the Newsgroups:
DialUp Networking by:Tibby
| I have probably asked this before, but can't find it. Does anyone know of a way that I can make a Dialup Networking Controller? I need to make a program such as NetZero's Dialer, and I know that the code is out there, I just can't findit. I am more than willing to use Win32 API if necessary.
Thanks, Tibby
| | | Reply: by:Tibby
| | | Just to clarify, I do not want to use the MarshelSoft component. There must be code somewhere, even if it's in C, to create/manage/delete DUN entries.
Thank You Tibby
| | | Reply: by:Supra
| | | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <title></title> </head> <body text="#000000" bgcolor="#ffffff"> <a class="moz-txt-link-abbreviated" href="http://www.vbip.com">www.vbip.com</a><br> <br> <br> Tibby wrote:<br> <blockquote type="cite" cite="midpck9e01o2se9dvlljksvvhuke8ttgpcfid@4ax.com"> <pre wrap="">On Thu, 01 Jul 2004 15:52:29 -0400, Tibby <a class="moz-txt-link-rfc2396E" href="mailto:tibby@tiberiansun.us"><tibby@tiberiansun.us></a> wrote:
</pre> <blockquote type="cite"> <pre wrap="">I have probably asked this before, but can't find it. Does anyone know of a way that I can make a Dialup Networking Controller? I need to make a program such as NetZero's Dialer, and I know that the code is out there, I just can't findit. I am more than willing to use Win32 API if necessary.
Thanks, Tibby </pre> </blockquote> <pre wrap=""><!----> Just to clarify, I do not want to use the MarshelSoft component. There must be code somewhere, even if it's in C, to create/manage/delete DUN entries.
Thank You Tibby </pre> </blockquote> </body> </html>
|
Posted by Xander Zelders
How do you call a child form from another child form?
Found the following interesting discussion in the Newsgroups:
how do you call a child form from another child form? by:SHAWN DEB ECKLEY
| Here is my situation... i have a parent window/ main app and i call a child form (type 1). the child form(type 1) gets information from a database. the user makes some choices and then some data is sent to the next child form(type2). i am having problems making this work.
I have tried instantiating the second child form right after the first from the parent window. this brings up both at the same time.
i have put the code for instantiating the second form in the first forms exit function. this makes the second form it's own parent form.
when i'm in the first form i can't seem to get the parent so that i can find the second form and show it. does any one have any ideas.
if i have all the code with in the parent form is there a way to make the code stop until the first form has finished ?
| | | Reply: by:The Grim Reaper
| | | Use ShowDialog() instead of just Show(). That'll stop processing in the calling sub until the form is closed or otherwise disposed. ____________________________________ The Grim Reaper
| | | Reply: by:SHAWN DEB ECKLEY
| | | Hi Grim I tried that and i got an error. because i'm making the forms child i can't use the showdialog() it only works with top level forms.
|
Posted by Xander Zelders
How to draw images on XP Style buttons?
Found the following interesting discussion in the Newsgroups:
Drawing images on XP Style buttons by:Max
| I finally figured out how to enable XP style on VB .NET apps, but now when I want a button to show an image it seems to disappear when the xp style is enabled. Actually the image disappears whenever a button's FlatStyle property is set to System which is what it has to be for XP Style to work. So my question is, what's the best way of showing an image on such a button. Preferably an image from an image list since I need transparency.
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
<URL:http://www.codeproject.com/cs/miscctrl/xp-style_button.asp>
-- Herfried K. Wagner
| | | Reply: by:Max
| | | Herfried K. Wagner [MVP] wrote:
Thanks for the link, but I don't think that method will work since I need my form to work both with xp style and without (like in Win 2k). The ideal case would be just to draw a picture on it, but I'm not sure how to do that.
| | | Reply: by:Mick Doherty
| | | http://dotnetrix.co.uk/buttons.html
-- Mick Doherty
| | | Reply: by:Jeff Johnson [MVP: VB]
| | | You may need to put code in the Paint event for the button and draw the image yourself with GDI+ methods. It's not the hardest thing in the world. I just learned how to do it myself when I was looking to put a downward-pointing arrow on a button, like "More v" (with the v representing the arrow).
|
Posted by Xander Zelders
Available IDE Macros ?
Found the following interesting discussion in the Newsgroups:
Available IDE Macros ? by:Jon Turner
| What is a method of gaining the path to the current project in the VS.NET IDE
I'm trying to add a Strong Name Key to the assembly file, but it want's the complete path name.
<Assembly: AssemblyKeyFile("ExcelToFile.snk")> 'Errors out, can't find file
I would like to do something like
<Assembly: AssemblyKeyFile(%ProjectPath\"ExcelToSalesForce.snk")>
What IDE enviroment variable can I use ?
Many Thanks In Advance
| | | Reply: by:Anonymous
| | | I don't think there is one that you can use the AssemblyInfo.vb file, but you can use relative paths. I believe it will look for the snk file relative to the build location, so if you're in release mode, then in the obj\release folder, etc
-- Erik Porter
|
Posted by Xander Zelders
Fun, but hopefully easy question
Found the following interesting discussion in the Newsgroups:
fun, but hopefully easy question by:Brad Allison
| Okay, I am grabbing data from a dinosaur, an AS400 system. One of the date fields is formated as decimal so the data adapter is filling the data set with these decimal numbers (ie 712004 for today or 10102001 for October 10, 2001).
Being fairly new with .net, is there an easy way to covert these decimal values into a usable date for vb?
Thanks for the information.
Brad
| | | Reply: by:Rob T
| | | Here's 2 functions I write long ago in the asp days that will do the trick....they may need a little tweaking to work with .net... Believe it or not we still use our 400 to run MAPICS. LOL
private function ConvertDate(inDate) ' Converts the stupid AS400 date into a normal date field dim StrMonth, strDay, strYear if len(indate) = 6 then inDate = "0" & inDate strYear = 1900+left(inDate, 3) strMonth = mid(inDate,4,2) strDay = right(inDate, 2) ConvertDate = strMonth & "/" & strDay & "/" & strYear end function
Private function ConvertDate400(inDate) ' Converts a normal date field into a stupid AS400 Mapics date dim StrMonth, strDay, strYear strMonth = month(inDate) if len(strMonth)=1 then strMonth = "0" & strMonth strDay = day(inDate) if len(strDay)=1 then strDay = "0" & strDay strYear = year(inDate)-1900 ConvertDate400=strYear & strMonth & strDay end function
|
Posted by Xander Zelders
Newsgroup praise.....
Found the following interesting discussion in the Newsgroups:
newsgroup praise..... by:SStory
| I just want to say thanks to the many people who take time to reply in this newsgroup. It has been a very valuable resource to me.
Pooling our collective knowledge allows us all to be better programmers.
Thanks,
Shane
| | | Reply: by:andreas
| | | I agree
|
Posted by Xander Zelders
How to paint 3D Edge on Ovals?
Found the following interesting discussion in the Newsgroups:
Painting 3D Edge on Ovals by:SStory
| You know there is the controlpaint.Draw3DBorder and it works great for rectangles. How can one do this on ovals.
'thi is my rectangle code ControlPaint.DrawBorder3D(g, rctShape.X, rctShape.Y, rctShape.Width, rctShape.Height, Border3DStyle.Sunken, Border3DSide.Top Or Border3DSide.Left Or Border3DSide.Right Or Border3DSide.Bottom)
Is there a way for ovals or do I need to design one.
If so, how?
Thanks,
Shane
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
You will need to design one.
-- Herfried K. Wagner
| | | Reply: by:SStory
| | | Thanks.
Any suggestions for how to do this and get the type of style listed below? Seem I will be either drawing 2 ellipses or many arcs.
I assume I should use systemcolors 3d light and the like also.
Any pointers?
Thanks
| | | Reply: by:Ken Tucker [MVP]
| | | Hi,
If you draw a white arc on half of the ellipse and black on the other it will appear 3d. If the white is on top it appears raised and the bottom it appears sunken.
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Dim g As Graphics = e.Graphics Dim pTop As New Pen(Color.White, 1) Dim pBottom As New Pen(Color.Black, 1) Dim rDraw As New Rectangle(400, 10, 50, 50) g.FillEllipse(Brushes.SkyBlue, rDraw)
g.DrawArc(pTop, rDraw, 0, 360) g.DrawArc(pBottom, rDraw, 0, 180) End Sub
Ken
| | | Reply: by:SStory
| | | I will give that a try Ken.
Thanks,
Shane.
|
Posted by Xander Zelders
jpeg to avi or other MS video format conversion
Found the following interesting discussion in the Newsgroups:
jpeg to avi or other MS video format conversion by:Zawar Qayyum
| I am using visual studio .NET with framework 1.0. I have a bunch of jpeg files, which I need to programmatically make a video out of. The video format is not an issue, as long as it can be run by Windows media player 9, and is in compressed format.
The language is VB.NET.
Thanks in advance Zawar
| | | Reply: by:Ken Tucker [MVP]
| | | Hi,
Here is a starting point. Unfortunately the code is in c#. http://www.codeproject.com/csharp/steganodotnet4.asp
Ken
|
Posted by Xander Zelders
How to save an xml stream to a file?
Found the following interesting discussion in the Newsgroups:
save an xml stream to a file by:kieran5405@hotmail.com (kieran)
| Hi,
I am trying to download a file through a proxy which is causing me lots of permission erors.
anyway after hacking at any and all code i could get my hands on, i got this far, where the xml file is in the sLine stream. now i want to save this stream to a local xml file but am having trouble doing this.
<code> Dim sURL As String sURL = "http://test/rss.xml"
Dim wrGETURL As WebRequest wrGETURL = WebRequest.Create(sURL) Dim saByPassList() As String Dim myProxy As New WebProxy("proxy:8080", True, saByPassList, New NetworkCredential("user", "password", "_domain")) myProxy.BypassProxyOnLocal = True
wrGETURL.Proxy = myProxy 'wrGETURL.Proxy = WebProxy.GetDefaultProxy()
Dim objStream As Stream objStream = wrGETURL.GetResponse.GetResponseStream()
Dim objReader As New StreamReader(objStream) Dim sLine As String = "" Dim i As Integer = 0
Do While Not sLine Is Nothing i += 1 sLine = objReader.ReadLine If Not sLine Is Nothing Then Console.WriteLine("{0}:{1}", i, sLine) End If Loop
Console.ReadLine()
</code>
Does anyone have any ideas for this.
| | | Reply: by:Ken Tucker [MVP]
| | | Hi,
Did you try something like this?
Dim dsXML As New DataSet dsXML.ReadXml("http://msdn.microsoft.com/rss.xml") dsXML.WriteXml("rss.xml")
Ken
| | | Reply: by:kieran5405@hotmail.com (kieran)
| | | Cheers for response Ken.
That would work fine only for the proxy i have to go through so i would need to feed the proxy and network credentials into the dataset connection. I have tried doing this but can't get it to work. Is this possible using the code.
i am a newbie so am probably completely off track. I would greatly appreciate if you could simply explain how to do this, or point me to a good tutorial.
Cheers for help. Ken Tucker
|
Posted by Xander Zelders
How to call an exe from vb.net?
Found the following interesting discussion in the Newsgroups:
calling an exe from vb.net by:Dave Cullen
| What's the correct way to run an external .exe file from within a VB.NET app? I had used code like below in VB6 before, but it doesn't work in .NET. Anybody have an equivalent?
'Function for executing an exe from VB6
Public Function ExecCmd(cmdline$) Dim proc As PROCESS_INFORMATION Dim start As STARTUPINFO ' Initialize the STARTUPINFO structure: start.cb = Len(start) ' Start the shelled application: ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _ NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc) ' Wait for the shelled application to finish: ret& = WaitForSingleObject(proc.hProcess, INFINITE) Call GetExitCodeProcess(proc.hProcess, ret&) Call CloseHandle(proc.hThread) Call CloseHandle(proc.hProcess) ExecCmd = ret& End Function
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
Have a look at the 'System.Diagnostics.Process' class and at the 'ProcessStartInfo' class.
-- Herfried K. Wagner
|
Posted by Xander Zelders
MergeOrder and MergeType
Found the following interesting discussion in the Newsgroups:
MergeOrder and MergeType by:Andrew McKendrick
| Hi,
I have a MDI form and an MDI child form both with menus.
The menu bar on the MDI form looks something like this:
MENUA MENUB MENUC MENUD
There is a single menu on the MDI child which I would like to insert in between MENUB and MENUC on the MDI form.
Can anyone tell me how to achieve this? I've tried looking at the help for the MergeOrder and MergeType properties - useless. I've also tried playing around with them - futile.
If you are wondering, as it stands right now, all menu items on both forms have a MergeOrder of 0 and the MergeType is the default (which I think is Add).
Thanks in advance,
Andrew
| | | Reply: by:Andrew McKendrick
| | | Hi,
I figured it out myself.
In case anyone is wondering:
I set the MergeOrder for the menus on the MDI form to 0, 1, 2, 3 respectively. And then set the MergeOrder for the menu on the MDI child to 1. And it works :-)
Andrew
|
Posted by Xander Zelders
Help with grid
Found the following interesting discussion in the Newsgroups:
Help with grid by:Anonymous
| Hi, Where can I find info on loading a grid with Hierarchical view or master/detail view so that the data is loaded and liiks like a treeview and when the user clicks the + sign the details is shown?
Thanks
| | | Reply: by:Ken Tucker [MVP]
| | | Hi,
Don’t know of any way to do that with the datagrid. Take a look the grid from component one that is included with vb.net resource kit.
http://msdn.microsoft.com/vbasic/vbrkit/default.aspx Ken
| | | Reply: by:Greg Burns
| | | But it can do that silly thing with a hyperlink to the child records. Although not a very friendly interface IMO.
Greg
|
Posted by Xander Zelders
Setup and deployment issue - won't let me include the clr
Found the following interesting discussion in the Newsgroups:
setup and deployment issue - won't let me include the clr by:Anonymous
| Hello, I have a setup and deployment project and when I build it I get the message dotNetFXRedist_x86_enu.msm must not be used to redistribute the .Net framework. Please exclude this merge module. However when I do exlcude it and try and run the .msi those users without the clr installed get the following message
These users do have the .net framework 1.1 installed, any idea how to overcome this problem. Regards Geri
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
Using Visual Studio .NET 2003 to Redistribute the .NET Framework <URL:http://msdn.microsoft.com/library/en-us/dnnetdep/html/vsredistdeploy1_1.asp>
Plug-In:
<URL:http://groups.google.com/groups?selm=z2an4EnoDHA.2012%40cpmsftngxa06.phx.gbl>
Bootstrapper:
<URL:http://msdn.microsoft.com/vstudio/downloads/tools/bootstrapper/>
Microsoft Visual Studio .NET 2003 Bootstrapper Plug-In <URL:http://www.microsoft.com/downloads/details.aspx?FamilyID=627921a0-d9e7-43d6-a293-72f9c370bd19>
<URL:http://workspaces.gotdotnet.com/vsboot/> (old URL)
Download <URL:http://www.gotdotnet.com/community/workspaces/newsitem.aspx?id=2f8f0a23-f529-4158-8e0a-d187d16f41f1&newsId=1981>
Framework 1.1:
Redistributing the .NET Framework 1.1 <URL:http://msdn.microsoft.com/library/en-us/dnnetdep/html/redistdeploy1_1.asp>
..NET Framework 1.1 Deployment Guide <URL:http://msdn.microsoft.com/library/en-us/dnnetdep/html/dotnetframedepguid1_1.asp>
..NET Framework 1.1 Redistributable Prerequisites <URL:http://msdn.microsoft.com/library/en-us/dnnetdep/html/NETFx1Redistreq1_1.asp>
..NET Framework Redistributable Package 1.1 Technical Reference <URL:http://msdn.microsoft.com/library/en-us/dnnetdep/html/dotnetfxref1_1.asp>
Framework 1.0:
..NET Framework Deployment Guide <URL:http://msdn.microsoft.com/library/en-us/dnnetdep/html/dotnetframedepguid.asp>
Using Visual Studio .NET to Redistribute the .NET Framework <URL:http://msdn.microsoft.com/library/en-us/dnnetdep/html/vsredistdeploy.asp>
-- Herfried K. Wagner
|
Posted by Xander Zelders
Bound Combo box
Found the following interesting discussion in the Newsgroups:
Bound Combo box by:Jack
| I have a form with a combo box that the items are being sourced from a dataset.
The problem is that the list only get populated after the form was previously opened; meaning, I open the form with the combo and the list is empty, then I close it and open it again and now it has data in the list.
The code that executes when the form is loaded is below:
CampaignSelectForm.DsCampaign1.Clear() CDsCampaign1.Clear() OleDbDataAdapter1.Fill(DsCampaign1) Combo1.DataSource = DsCampaign1.campaign Combo1.DisplayMember=DsCampaign1.campaign.campaignColumn.To String Combo1.Refresh()
| | | Reply: by:William Ryan eMVP
| | | Check the Rows.Count property of the datatable. Also, why are you calling ..Clear() twice?
--
W.G. Ryan
| | | Reply: by:jack
| | | The two clears were a typo (actually a cut and paste-o), it is not in the code that way.
The row count of the underlying table is three (3) and three items show up when the form is closed and reloaded. Output form the Immediate Window: ?DsCampaign1.Tables.Item("campaign").Rows {System.Data.DataRowCollection} Count: 3 IsReadOnly: False IsSynchronized: False Item: <cannot view indexed property> SyncRoot: {System.Data.DataRowCollection} ?DsCampaign1.Tables.Item("campaign").Rows.Count 3
Jack
| | | Reply: by:
| | | Additional Info: When I walk through the code Combo1.DataSource always is nothing on the first load. Even after the call to: Combo1.DataSource = DsCampaign1.campaign and after I try to manuall assign it to the datatable via any of the ways: DsCampaign1.tablecampaign DsCampaign1.Tables("Campaign")
I can also look at in the immed window and it has data.
| | | Reply: by:Jack
| | | Problem solved.
It must have had to do with the migration of the control. I deleted the control and re-added it and not it works fine.
|
Posted by Xander Zelders
ShowDialog() =?= Dispose()?
Found the following interesting discussion in the Newsgroups:
ShowDialog() =?= Dispose()? by:Phill. W
| Under what circumstances could a Form, displayed modally using ..ShowDialog, be instantly and untrappably Dispose'd??
I've built a MsgBox replacement but, in one application, it gets called with the contents of an Exception and, instead of ShowDialog() popping up the dialog, buttons and all, it "sort of" puts up the "outline" of the dialog, but immediately Dispose's it - dialog.IsDisposed = True immediately after the .ShowDialog call.
In another application, however, it works perfectly.
/Any/ Suggestions?
TIA, Phill W.
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
Post your code.
-- Herfried K. Wagner
| | | Reply: by:Phill. W
| | | Un-be-lievable!!
I've found and fixed the problem, but I'm not entirely sure I understand just /why/ it's happening in the first place.
My dialog was being shown from the Click event handler on a [Close] button in an /inherited/ form. The base form, of course :-/ - had code in the ancestor [Close] button to Close() the base form. So, by the time my derived Close button Click-hander was invoked and wanted to show my dialog, the base form had been Close()'d and Dispose()'d.
All that I can understand - /now/ - but the bit that's got me stumped is this; my dialog resizes itself based on the text it has to display, so it uses Graphics.MeasureString() on the "prompt" value I give it. Fine, except that I have to get a Graphics object from somewhere so, within my "MsgBox" Form, I'm using
Dim g As System.Drawing.Graphics _ = System.Drawing.Graphics.FromHwnd(Me.Handle)
If the form I'm launching my dialog from has already been Disposed(), this line throws an ObjectDisposedException, but "Me" /hasn't/ been Dispose()'d - the form /from which/ I'm launching this [dialog] form has! The "MsgBox" form is not inherited from (nor otherwise related to) the form that's trying to ShowDialog() it (indeed, I replaced my dialog with a "New Form" and got exactly the same symptoms.
Is there some implicit realtionship between the [Window handle of a] form that launches a dialog and that of the dialog itself? Or, more likely, is the above code the /wrong/ way to get hold of a Form's graphics object?
TIA, Phill W.
| | | Reply: by:Anonymous
| | | It sounds like you have an exception happening while processing the ShowDialog function. You stated that the exception stack trace is being shown. Track that down to see where the exception is happening.
HTH -- David Williams
|
Posted by Xander Zelders
GDI........... textbox
Found the following interesting discussion in the Newsgroups:
GDI........... textbox by:Supra
| How do i get highlight off when the form is loaded. I don't textbox be hightleighted. ne ideas u can give me an hint?
Dim txthelp As New TextBox With txthelp .Parent = Me .Dock = DockStyle.Fill .WordWrap = True .Multiline = True .ScrollBars = ScrollBars.Vertical end with regards,
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
What do you mean by highlighted? Assign a 'TabIndex' to the textbox that so that it is not the first control that receives focus after the form is shown.
-- Herfried K. Wagner
| | | Reply: by:Supra
| | | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <title></title> </head> <body text="#000000" bgcolor="#ffffff"> at runtime i get all highlighted.when i clicked it, it will not highlighted anymore. . u can try with code and c what happened.<br> regards,<br> <br> Herfried K. Wagner [MVP] wrote:<br> <blockquote type="cite" cite="mid2kirivF2t6r6U4@uni-berlin.de"> <pre wrap="">* Supra <a class="moz-txt-link-rfc2396E" href="mailto:supra56@rogers.com"><supra56@rogers.com></a> scripsit: </pre> <blockquote type="cite"> <pre wrap=""> How do i get highlight off when the form is loaded. I don't textbox be hightleighted. </pre> </blockquote> <pre wrap=""><!----> What do you mean by highlighted? Assign a 'TabIndex' to the textbox that so that it is not the first control that receives focus after the form is shown.
</pre> </blockquote> </body> </html>
|
Posted by Xander Zelders
'download a file through proxy' code problem
Found the following interesting discussion in the Newsgroups:
'download a file through proxy' code problem by:kieran5405@hotmail.com (kieran)
| Hi,
I am trying to download a file from the Internet. The below code works fine with no proxy server but I am behind a proxy server at work and need to figure out how to include it in the code.
<code> Dim wc As New System.Net.WebClient wc.DownloadFile("http://www.google.ie/images/hp0.gif", _ "C:\inetpub\wwwroot\bin\google.gif") </code>
I have been looking all over google and am trying the following code but as i am not familar with vb.net i can not get the structure right or am not sure if this is the way to do it. <code> dim ProxyObject as New WebProxy= new webProxy(Http://proxyserverIP:8080,true) dim cred as NetworkCredential= new NetworkCredential("User","password","domain") ProxyObject.Credentials=cred GlobalProxySelection.Select=proxyObject <code> Thanks for any and all help.
| | | Reply: by:Patrick Steele [MVP]
| | | I've never gove through a proxy, but the above code looks correct.
However, the WebClient class doesn't have a Proxy property but the WebRequest class does. You may have to use the WebRequest object and stream the data into the file yourself.
-- Patrick Steele
| | | Reply: by:kieran5405@hotmail.com (kieran)
| | | Hi Patrick,
Cheers for response.
I have been trying what you said and can get the stream to read but can not see how to write it. I am using the following code and keep getting the error -
I see from other messages it may be something to do with 'Keep-alive' but when i put in that line, it brings back an error. Or it may be that the write syntax of my code is wrong.
Any help greatly appreciated. ------------------------ <code> Dim sURL As String sURL = "http://test.com/rss.xml"
Dim wrGETURL As WebRequest wrGETURL = WebRequest.Create(sURL)
Dim saByPassList() As String Dim myProxy As New WebProxy("proxy:8080", True, saByPassList, New NetworkCredential("user", "password", "_domain")) myProxy.BypassProxyOnLocal = True
wrGETURL.Proxy = myProxy
Dim objStream As Stream objStream = wrGETURL.GetResponse.GetResponseStream() Dim myFileName As String = "C:\rss.xml" Dim myFileStream As New StreamWriter(objStream) myFileStream = File.CreateText(myFileName) </code>
---------------------------------------
Patrick Steele
|
Posted by Xander Zelders
DataSet
Found the following interesting discussion in the Newsgroups:
DataSet by:Fabian
| Hello everybody, I would like to know if someone can help me with a DataSet. In my case the select command that fills the DataSet is a view (sql2000) that contains 10 tables, I have defined the SQLDataAdapter as follows: Dim SqlAdapter As New SqlDataAdapter("SELECT * FROM vw_DG_PERSONAS", SqlCon) En evento Load del Frm tengo esto: SqlCon.ConnectionString = "Server=" & Svr & _ SqlAdapter.Fill(DsPersonas, "vw_DG_PERSONAS") SqlCon.Close() DataGrid1.DataSource = DsPersonas DataGrid1.DataMember = "tbl_per_personas"
My problem is that the window has a DataGrid that shows the view, and I modify the data, then I want to save the changes to the SQL DB, so I do the following:
SqlAdapter.Update(DsPersonas), and here this error occurs: (Update can not find TableMApping('Table') o DataTable 'Table')
Please i someone can help me on working with DataSet, just tell me, Thanks.
| | | Reply: by:SStory
| | | Well, I think Adapters update tables and not dataset so maybe you would need to specify the table in the database to update.
Thanks.
| | | Reply: by:Brad Allison
| | | Fabian,
SqlAdapter.Update(DsPersonas, "Table") -or- SqlAdapter.Update(DsPersonas, <index of table>)
Hope this helps.
Brad Thanks.
|
Posted by Xander Zelders
Error Starting APP in the GDI
Found the following interesting discussion in the Newsgroups:
Error Starting APP in the GDI by:jcrouse
| I moved a bunch of code and variable declaration around to make things a little more efficient. Now when i try and run the app I get the following error:
An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module. Additional information: Object reference not set to an instance of an object.
The problem is that i can't debug it. I have put breakpoints everywhere and can't find the problem. In my startup module everything seems to initialize properly. I then run the following code:
Application.Run(frm1) Inside the load event for this form i step through everything and it all seem good. Here is the load event:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strFiles() As String = Directory.GetFiles(Application.StartupPath & "\Layout Files")
If strFiles.Length > 0 Then
mnuMainNewConfig.Enabled = True
End If
bSaveTrigger = False
frm1.strExitKey = ""
End Sub I get all the way through to the end sub then when i click the "step into" button the error occurs. I don't know how to debug deeper or what to do next. Please help.
Thank you, John
| | | Reply: by:jcrouse
| | | More....When I select the break button, I get the following error:
There is no source code available for the current location.
I'm sure I moved something wrongly, I just don't know how to find out what.
Thnaks again,
John
| | | Reply: by:Anonymous
| | | To your startup module, add handlers for the UnhandledException and Threading.ThreadAbortException. The stack trace in the exception (most likely ThreadAbortException as you are running a WinForm) will give the line of code causing the problem.
HTH -- David Williams
| | | Reply: by:jcrouse
| | | Well....I seem to have found it. This piece of code was wrong:
If strMyStartupArguments.Length = "1" Then
If frm1 Is Nothing OrElse frm1.IsDisposed Then
frm1 = New Form1
End If
myForms.form1 = frm1
Application.Run(frm1)
Exit Sub
End If I needed to read like this:
If strMyStartupArguments.Length = "1" Then
If frm1 Is Nothing OrElse frm1.IsDisposed Then
frm1 = New Form1
End If
Application.Run(frm1)
myForms.form1 = frm1
Exit Sub
End If Can someone explain this so I understand?
Thank you, John
|
Posted by Xander Zelders
Class properties
Found the following interesting discussion in the Newsgroups:
Class properties by:Rob T
| OK....trivial question, but would be nice to have....:
Let's say I have simple class like this:
Public Class EMailer Public [To] As String ' The Internet address of the recipient Public From As String ' The Internet address of the sender
Public Function Send() As String 'sends the message Return [To] & "-" & From End Function End Class
Now in the main code when I'm typing in my code like this:
dim mail as new EMailer mail.to="Rob"
When I'm typing and get to the "." the visual designer shows me what objects are available. How do you create the class so that the little descriptions show up when you hover over each object?
-Rob T.
| | | Reply: by:Mythran
| | | There are 3rd party utilities that allow you to do this in VB.Net but no way to do it w/o them. C# uses the code comments for intellisense descriptions and VB.Net has not been brought up to speed with them.
One of the many advantages of C# over VB.Net. But still, not enough for most people that use VB.Net to convert.
Bah!
Mythran
| | | Reply: by:Rob T
| | | Thanks.... I guess I'll have to suffer with non-descriptive classes!
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | |
I would use properties in this situation.
My FAQ:
Adding tooltips in intellisense for VB.NET assemblies:
VS.NET takes the text shown in intellisense tips from an XML file that is provided in addition to the assembly (for example, a DLL). The XML file must have the same name as the corresponding DLL with ".xml" appended and must be placed in the same folder as the assembly (assembly "Foo.dll", XML file "Foo.dll.xml").
The format of the XML file taken by VS.NET is specified here:
<URL:http://msdn.microsoft.com/library/en-us/csref/html/vclrfprocessingxmlfile.asp>
For C#, VS.NET creates this XML file automatically (compiler option possible in VB 2005.
You can create the XML file by hand, but notice that this will take a lot of time and it will be hard to update the file if parts of the assembly change. It's much easier to use one of the tools listed below to create the XML file. Tools like NDOC will take the XML file and can be used to create an HTML Help file from this data.
One easy way is to provide information for tooltips as XML comments inside the source files and then use tools like VB.DOC to create the XML file that contains the data. Then you can copy this file into the assembly's directory to provide information to VS.NET that enables it to display tooltips, or you can create a help file. The help file can be deployed with the assembly and can be used by other developers who use the assembly as reference.
For VB.NET 2002/2003:
My XML Comments FAQ:
VB Commenter <URL:http://www.gotdotnet.com/team/ide/> -> "VB Commenter"
XML Documentation <URL:http://www.gotdotnet.com/team/vb/> -> "XML Documentation"
VBXC - VB.NET XML Commentor <URL:http://vbxmldoc.tor-erik.net/>
NDOC (formerly DOC.NET) <URL:http://ndoc.sourceforge.net/>
VB.DOC <URL:http://vb-doc.sourceforge.net/>
<URL:http://www.gotdotnet.com/Community/Workspaces/Workspace.aspx?id=112b5449-f702-46e2-87fa-86bdf39a17dd>
XML comments will be introduced to VB in version 2005 ("Whidbey").
C# XML comments:
C# Programmer's Reference -- Recommended Tags for Documentation Comments <URL:http://msdn.microsoft.com/library/en-us/csref/html/vclrfTagsForDocumentationComments.asp>
-- Herfried K. Wagner
|
Posted by Xander Zelders
0 or 1 vs True or False
Found the following interesting discussion in the Newsgroups:
0 or 1 vs True or False by:Wayne Wengert
| I am using VB in a VSNET 2003 Windows application. I've run into a situation where, when trying to set a bit value in a SQL Server 2000 database I get errors because the values extracted from a datarow return True or False. In the snippet below, the SQL becomes "Update myTable SET EQ = True" which fails with an error that "True" is not a valid column name? I gather that the datarow object returns True or False for bit fields? I can always recode this to get around the problem but I am trying to understand what the rules are here?
========== Sample Code ============= Dim dr As DataRow If chkEqp.Checked Then dr("EQ") = 1 Else dr("EQ") = 0
' If I need to manually do the update I use this code
| | | Reply: by:Mythran
| | | If CInt doesn't work (nor CDbl) try doing:
Can't remember if SQL Server's True is -1 or 1, try -1 if 1 doesn't seem to work, although I think both will work.
Hope it helps :)
Mythran
| | | Reply: by:Wayne Wengert
| | | Thanks for that suggestion.
Wayne
| | | Reply: by:Stephany Young
| | | This raises a number of matters that need to be understood to arrive at the best solution for you.
In SQL Server, the bit data type should not be considered to be boolean. Whereas a boolean can be True or False (and nothing else), the bit data type can be 0, 1 or NULL. To digress, the fact that it can be NULL, in my experience, causes headaches, and I always declare a bit as NOT NULL with default of 0.
In VB, the boolean datatype can be True oe False. Although a boolean can be represented numerically as -1 for True and 0 for False, on should always think of a boolean in terms of True or False and forget about the underlying numerical values. The difference between VB and other languages that have 1 as their 'True' value is due to the historical fact that in BASIC, True is actually calculated as Not False. If you do a bitwise NOT on 0 the result is -1. Over the years the language has evolved so that any non 0 value will resolve to True.
In a DotNet datatable, a SqlDBType.Bit will be interpreted as a System.Boolean and the translation of 1 and 0 to True and False respectively (and the reverse) is handled by the Framework.
If you do things the DotNet way, thus:
Dim _com As New SqlCommand("Update myTable SET EQ=@EQ", _sqlcon) _com.Parameters.Add(New SqlParameter("@EQ", SqlDBType.Bit)). |
| |