
TedN
Avatar/Signature-
Posts
35 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by TedN
-
OK. I found the problem. I downloaded and installed Unlocker and it showed the only process that was using the dat file was Visual Studio. So it was obviously my code. By a process of elimination Unlocker was able to show when the dat file became used. And there it was, right at the beginning of the program where I opened a streamreader to check the password. I'd forgotten all about that - most embarrassing. I hadn't closed out the streamreader completely. Strange the program worked OK in VS 2003.
-
My program firsts reads a file then writes to the file. The program used to work fine on my old XP Home OS and using Visual Studio 2003. I've since changed to XP Pro and installed Visual Studio 2005. I now get the following error: "The process cannot access the file "C:\Haven.dat" because it is being used by another process." It's got something to do with Haven.dat still being in use. The relevant code is as follows: Public Function Decrypt() As Integer Dim fsRead As FileStream Dim encStream As CryptoStream Dim sr As StreamReader fsRead = New FileStream("C:\Haven.dat", FileMode.Open, FileAccess.Read) encStream = New CryptoStream(fsRead, key.CreateDecryptor(), CryptoStreamMode.Read) sr = New StreamReader(encStream) fsRead.Close() encStream.Close() sr.Close() fsRead.Dispose() encStream.Dispose() sr.Dispose() End Function Public Function Encrypt() As Integer Dim fsWrite As New FileStream Dim encStream As CryptoStream Dim sw As StreamWriter [b]fsWrite = New FileStream("C:\Haven.dat", FileMode.Create, FileAccess.Write)[/b] encStream = New CryptoStream(fsWrite, key.CreateEncryptor(), CryptoStreamMode.Write) sw = New System.IO.StreamWriter(encStream) fsWrite.Close() encStream.Close() sw.Close() fsWrite.Dispose() encStream.Dispose() sw.Dispose() End Function The error occurs at the bolded line. As a test I made a copy of the dat file and referenced the copy in the bolded line. There was then no error so it means that the original dat file is not being closed down. Your help would be much appreciated.
-
Found the answer. I needed to use sender instead of ctl in the following lines of code. If TypeOf sender Is Label Then MsgBox(sender.Name) End If
-
I have a form with a multitude of labels. I would like to code a generic event handler so that a click on any of the labels would fire a single event. The following code was adapted from a search on this site. I have set it up so that when a label is clicked the label name should be displayed in a message box. For this test case I only have two labels (Label1, Label2) on a form. The problem is that the message displayed is always "Label1" regardless as to whether I click on the form, Label1 or Label2. Public Class Form1 Inherits System.Windows.Forms.Form Dim ctl As Control Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load AddGenericClickHandler(Me, AddressOf Generic_Click) End Sub Sub Generic_Click(ByVal sender As Object, ByVal e As EventArgs) If TypeOf ctl Is Label Then MsgBox(ctl.Name) End If End Sub Private Sub AddGenericClickHandler(ByVal Parent As Control, _ ByVal Handler As EventHandler) For Each ctl In Parent.Controls AddHandler ctl.Click, Handler Next AddHandler Parent.Click, Handler End Sub End Class Your help would be much appreciated. Thanks, Ted
-
Duh! I was removing column before making datagridview visible. Make it visible first and column can be removed.
-
Is there a way to remove a column from a DataGridView. I fill the datagridview from a dataset. The dataset has a column of data that I no longer require. I've tried getting rid of the column in the dataset without success. ds.Tables("Asset").Columns(6).Dispose() doesn't appear to do anything. So I then tried to remove the column from the datagridview. I've tried: dgPrio.Columns.Remove("CLASS") dgPrio.Columns.RemoveAt("CLASS") and various other combinations. All that happens is the column I wish to remove moves to the end. Appreciate any help. Thanks, Ted
-
Re: DataGridView.CellPainting Thanks for your code, it works fine. Very much appreciated. Just gotta find the way of increasing the header height. Thanks again, Ted
-
Re: DataGridView.CellPainting Thank you for this. It's beginning to sink in that with Graphics one needs a sub routine that repaints on an as required basis, as you mentioned in one of your previous posts. I won't be able to get back to this until next week. But I look forward to trying this out and hopefully with some success. Thank you again for all your help. TedN
-
I really appreciate all the advice. However, I think I'm reaching the end of the line here. What I really wanted to do was to put vertical text in the column headers of a DataGridView. I have fairly lengthy column headers which can't really be shortened. This means that the columns are unnecessarily wide. This work was originally displayed on an Excel spreadsheet where there's no problem aligning the column header text vertically. If I'm having this much of a problem with a simple label then I think that DataGridView column headers are well beyond my reach. If anyone out there knows of an alternative to a DataGridView where column header text can be displayed vertically I'd appreciate knowing. Thanks for your time. Ted
-
Thanks for all of your replies. I've modified the code so that when the form loads it calls a sub routine which should cause vertical text to appear on a label. The program runs but the label remains blank. Appreciate it if someone could point me to what I'm doing wrong. Public Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load VertText(Label1) End Sub Private Sub VertText(ByVal control As Control) Dim sName As String = "TedN" Dim g As Graphics = control.CreateGraphics Dim oBrush As New SolidBrush(Color.Black) Dim oFont As New Font("Tahoma", 32, FontStyle.Bold) Dim oStrFormat As New StringFormat(StringFormatFlags.DirectionVertical) g.DrawString(sName, oFont, oBrush, 0.0F, 0.0F, oStrFormat) End Sub Thanks, TedN
-
The following code causes a string to be written vertically on a form. The code runs automatically when the form is opened. Public Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As PaintEventArgs) Handles MyBase.Paint Dim sName As String = "TedN" With [b]e[/b].Graphics Dim oBrush As New SolidBrush(Color.Black) Dim oFont As New Font("Tahoma", 32, FontStyle.Bold) Dim oStrFormat As New StringFormat(StringFormatFlags.DirectionVertical) .DrawString(sName, oFont, oBrush, 0.0F, 0.0F, oStrFormat) End With End Sub I would like to put the code in a simple little sub routine that would be called when the form loads or a button clicked, etc. I've tried every whichway to get rid of the "e" component which I assume is tied to an event. I don't want the code to run directly from an event. How the heck do I do that. Thanks, Ted
-
I currently download data from a database into a Dataset table, then display the data in a DataGridView. I would like to sort on more than one column at a time in the DataGridView. Can this be done? Also, my column headings need to be quite descriptive which leads to unnecessarily wide columns. Is there a way of turning the text on its side (as in an Excel spreadsheet) to allow narrower columns. Thanks, Ted
-
OK. Found the answer. Use two DataAdapters.
-
I've created two query strings to get data from various tables in a database. I would like to fill two table tables in a dataset with the data from each query string, e.g. sqlStr1 data into dsTable1 sqlStr2 data into dsTable2. I've tried the following and many other combinations but none seem to work. con.Open cmd.CommandText = sqlStr1 da.Fill(ds, "dsTable1") cmd.CommandText = sqlStr2 da.Fill(ds, "dsTable2") con.Close I don't need any interoperability between the two tables. I'm placing the data in separate tables simply for the sake of clarity. I would also prefer not to combine the two query strings. Thanks, Ted
-
OK. I finally got it to work. Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim da As OleDb.OleDbDataAdapter Dim cmd As New OleDb.OleDbCommand Dim con As OleDb.OleDbConnection Dim ds As New DataSet Dim dv As New DataView Dim sql As String da = New OleDb.OleDbDataAdapter(cmd) con = New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" _ & "Data Source = C:\AddressBook.mdb") sql = "SELECT * FROM tblContacts WHERE Surname = @sName" cmd.Parameters.Add("@sName", OleDb.OleDbType.Char).Value = "Smith" cmd.Connection = con cmd.CommandText = sql con.Open() da.Fill(ds, "Test") con.Close() dv.Table = ds.Tables("Test") Me.DataGrid1.DataSource = dv End Sub Can't say I've got a complete handle on it yet but it's a start.
-
Thanks for your reply. I'm getting an error regarding: da = New OleDb.OleDbDataAdapter(sql, con) With the use of parameters, the variable sql isn't set to anything. What would I put in DataAdapter statement. Thanks, Ted
-
Yup. That should do it. I've also sorted out the data repeat. The table was updating when I used ds.Tables("Test").Clear(). I was being lazy and instead of actually changing the data in the datagrid and then clicking the button I simply did a sort to change the data around. Thanks, Ted
-
Thanks Amir. I've now done everything during design time and the only code I have is: Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click con.Open() da.Fill(ds, "Test") con.Close() End Sub This works fine but how do I assign different column widths to the datagrid. TableStyles gives me a preferred column width which applies to all columns. If I add a Member in TableStyles then add GridColumnStyles Members each with its own width, it is totally ignored. I'm obviously out to left field here. Also, each time I click the button the data repeats itself. Anyway to clear the datagrid. I've tried ds.Tables("Test").Clear() which stops the repeat but the datagrid isn't updated. Thanks, Ted
-
Thanks for your reply Amir. I was earlier pointed to a couple of links which showed the use of parameters. I then tried to use this info to run my small test program. That's when I got stuck. Maybe the best way to explain it is to show you my test program using a sql string and then show the example I tried to utilize at one of the links. Test Program Private Sub btnLoad_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnLoad.Click Dim con As New OleDb.OleDbConnection Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String Dim dv1 As New DataView con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _ & "Data Source = C:\AddressBook.mdb" sql = "SELECT * FROM tblContacts WHERE Surname = 'Smith'" con.Open() da = New OleDb.OleDbDataAdapter(sql, con) da.Fill(ds, "Test") con.Close() dv1.Table = ds.Tables("Test") Me.DataGrid1.DataSource = dv1 End Sub End Class Parameter Example (C#) set your sql string = to something like cmd.CommandText = "SELECT * FROM MYTABLE WHERE NAME = ? and DOB > ?" then add parameters for each of your '?' like this: cmd.Parameters.Add(new OleDbParameter("NAME", OleDBType.VarChar); cmd.Parameters.Add(new OleDbParameter("DOB", OleDBType.DateTime); prepare your command. This compiles your command for faster execution. Command Preparation is implicit and does not really need to be called as it will be called internally the first time the command is executed. In some rare cases explicitly calling it can speed performance. cmd.Prepare your cmd is ready to be used by just setting the parameter values: cmd.Parameters["NAME"] = "Miller"; cmd.Parameters["DOB"] = DateTime.Parse("12/2/1959"); cmd.ExecuteReader(); If you could show me how my test program could be implemented using parameters I would be much obliged. Thanks, Ted
-
Thanks for the info. I checked the links you provided and have looked up various sites for sql parameters. I'm still struggling a bit though to get parameters to work and would appreciate it if you could tell me where I'm going wrong. Following is some basic code that should select names from a database if the name in third column is "Smith". Private Sub btnLoad_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnLoad.Click Dim con As New OleDb.OleDbConnection Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String = "" con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _ & "Data Source = C:\AddressBook.mdb" con.Open() Dim cmd As New OleDb.OleDbCommand("Select * from tblContacts where Column2 = ?", con) [b]cmd.Parameters(0).Value = "Smith"[/b] [i]da = New OleDb.OleDbDataAdapter(sql, con)[/i] da.Fill(ds, "Test") con.Close() txtFirstItem.Text = ds.Tables("Test").Rows(0).Item(1) txtSecondItem.Text = ds.Tables("Test").Rows(0).Item(2) End Sub The error I get is: (Bolded line) "Additional information: Invalid index 0 for this OleDbParameterCollection with Count=0." Also, what do I do with DataAdapter line (Italics) if I no longer have the sql string. Thanks, Ted
-
This is a pretty basic question so you'll see how far down I am on the learning curve. I'm building a sql string and the whole thing is getting rather unwieldy. So I'm wondering if there is a way to insert sql code not as a string but as a separate sub routine or code section. I can then build the string within the sql sub routine. If this is possible how does one define it as sql code and not vb. Thanks, Ted
-
Thanks Nate. I'll try coding the style. Ted
-
I've created a data grid with the form designer and set the various column widths and headings. However, when I display the data in the data grid the column widths change back to the default and the headings are the database column headings. The code I'm using to display the data grid is: Me.dg1.DataGrid.DataSource = ds.Tables("Asset1") where dg1 is the data grid and ds the dataset. The only way I can find to get the right headings is to define them in the sql string. How can I keep my original data grid settings which I did in the form designer. Thanks, Ted
-
Can anyone point me to a good skinning tutorial or book. I would like to "tart up" a VB.Net application I put together but know absolutely nothing about skins. There appears to be two paths I can take. Build my own images using Paintshop Pro or acquiring a skin editor like SkinCrafter. My preference is to build and apply my own images. Any info much appreciated. Thanks, Ted
-
Determining Status of FileStream, etc.
TedN replied to TedN's topic in Directory / File IO / Registry
Thanks Paul. That solved my problem Regards, Ted