|
.equals is for comparing things other than numbers or words, like controls.
if textboxTMP.equals(textboxName) kind of thing, if you're working with say, forms or addressbooks and you need to have some sort of checking rather than a loop or select for each control. Personally, I don't use it, so I can't think of a useful instance, though I'm sure there are a few.
Daniel
|
|
|
|
|
I'd appreciate the code necessary to retrieve data from a column in a table. I'm setting up a public function in a module. I'm used to working with Access recordsets and am confused with .net. I need to get through this mental barrier. Thanks
|
|
|
|
|
I, too started with Access ... and have struggled with .NET ...
In this example, I am using two tables, "tblProjects" and "tblContacts" from my target Access Database, which we will call "Target.mdb"
I use a "WinComboBox" control from Xceed Software in Montreal, Canada (which will probably answer one of the next questions in your mind) which allows a multi-column ComboBox Dropdown ala Access-Style. Using the code below, I duplicate two of the most useful features of Access ... being able to select from a combobox and SEE multiple columns of data to better identify what I am selecting and... approximate the Form/Subform capability of Access as well.
Hope this helps you.
This is my first post here and I have NO clue as to how to attach a zip of the VS.NET 2005 Project ... so here is the code:
==========================================================================
Imports System
Imports System.Data
Imports System.Xml
Public Class Form1
Dim Con As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Target.mdb")
Dim dsProjectList As New DataSet
Dim daProjectList As OleDb.OleDbDataAdapter
Dim dsProjectSelected As New DataSet
Dim daProjectSelected As OleDb.OleDbDataAdapter
Dim dsContactSelected As New DataSet
Dim daContactSelected As OleDb.OleDbDataAdapter
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Open Connection to Target Access Database
Con.Open()
'Fill Project List, daObjectName=DatAdapter, dsObjectName=DataSet, tblTableName=Table in Target Database
daProjectList = New OleDb.OleDbDataAdapter("SELECT tblProjects.P_ID, tblProjects.P_Name,tblProjects.P_Client_ID FROM tblProjects", Con)
dsProjectList.Clear()
daProjectList.Fill(dsProjectList, "tblProjects")
'Xceed WinComboBox .NET Component, Multi-Column ComboBox Control
wcbxProjectSelected.DataSource = dsProjectList.Tables("tblProjects")
wcbxProjectSelected.ColumnWidthAdjustment = Xceed.Editors.ColumnWidthAdjustment.FitToItems
'Close the Connection to Target Access Database
Con.Close()
End Sub
Private Sub wcbxProjectSelected_SelectedItemChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles wcbxProjectSelected.SelectedItemChanged
Dim strSelectedText As String
Dim SelIdx As Integer
Dim ProjID, sqlProject As String
Dim ContactID, sqlContact As String
'Get String of Selected Text from WinComboBox
strSelectedText = wcbxProjectSelected.TextBoxArea.SelectedText.ToString
'Catch Empty SelectedText
If Not IsDBNull(strSelectedText) Then
'Get Currently Selected Row from the WinComboBox Control
SelIdx = wcbxProjectSelected.SelectedIndex
'Get the ProjectID from Column1 of the WinComboBox Control (by "Named Field" Method)
ProjID = dsProjectList.Tables("tblProjects").Rows(SelIdx).Item("P_ID")
'Get the ContactID from Column3 of the WinComboBox Control (by "Named Field" Method)
ContactID = dsProjectList.Tables("tblProjects").Rows(SelIdx).Item("P_Client_ID")
'Open Connection to Target Access Database
Con.Open()
'Define SQL Statement to get a single row based on the selected ProjectID
sqlProject = "SELECT tblProjects.* FROM tblProjects WHERE tblProjects.P_ID = " + ProjID
'Create the new ProjectSelected DataAdapter, then FILL it with data from the DataSet
daProjectSelected = Nothing
daProjectSelected = New OleDb.OleDbDataAdapter((sqlProject), Con)
dsProjectSelected.Clear()
daProjectSelected.Fill(dsProjectSelected, "tblProjects")
'Fill Individual TextBox Controls on Form1; note use of Iff Function to trap Nulls in Database Fields
TextBox1.Text = wcbxProjectSelected.SelectedIndex + 1 'Selected Record Number; WinComboBox is 0-based, Records are 1-based
Me.TextBox2.Text = IIf(IsDBNull(dsProjectSelected.Tables("tblProjects").Rows(0).Item("P_ID")), "", dsProjectSelected.Tables("tblProjects").Rows(0).Item("P_ID"))
Me.TextBox3.Text = IIf(IsDBNull(dsProjectSelected.Tables("tblProjects").Rows(0).Item("P_Name")), "", dsProjectSelected.Tables("tblProjects").Rows(0).Item("P_Name"))
'Define SQL Statement to get a single row based on the selected ContactID
sqlContact = "SELECT tblContacts.* FROM tblContacts WHERE tblContacts.C_ID = " + ContactID
'Create the new ContactSelected DataAdapter, then FILL it with data from the DataSet
daContactSelected = New OleDb.OleDbDataAdapter((sqlContact), Con)
dsContactSelected.Clear()
daContactSelected.Fill(dsContactSelected, "tblContacts")
'Fill the DataGridView Control on Form1
DataGridView1.DataSource = dsContactSelected.Tables("tblContacts")
'Close the Connection to Target Access Database
Con.Close()
End If
End Sub
End Class
D=
|
|
|
|
|
Thanks, but I already have a connection, and I'm passing the id of the row to the function. I'd just like to get the data from that row and return it to the program I'm writting. There must be an easier way. Thanks
|
|
|
|
|
Thanks guys, but I guess it was to easy to answer, or you figured I needed to get it on my own, so I did. Thanks
|
|
|
|
|
Hello !
I develop a program which upload a file (max 10Mo) to a server with POST METHOD.
For little files, there is no problem. But for files of 6Mo and more, the upload don't finish. I think that I upload data too quickly. With Ethereal, I saw my data. There is a frame of 1452 bytes, after a frame of 96 bytes, another of 1452 etc...
Another software (perhaps writted in C/C++) upload the data with frames of 1024 bytes. And it works perfectly.
How can I change the data buffer of TCP in .NET 2 ?
I tried to change the "BufferSize" of my stream "rs" but no change.
I post a little part of my program :
Private request As HttpWebRequest
Const BufferSize As Integer = 1024
Dim content As Byte() = New Byte(BufferSize - 1) {}
Dim dataRead As Integer
Dim fs As Stream = getStream(Me.data)
Using rs As Stream = Me.request.GetRequestStream
While True
dataRead = fs.Read(content, 0, BufferSize)
If dataRead = 0 Then
Exit While
End If
rs.Write(content, 0, dataRead)
dataReads += dataRead
RaiseEvent PercentDone(dataReads, Me.data.Length)
End While
fs.Flush()
fs.Close()
End Using
Sorry for my poor english.
Thank you for reading.
|
|
|
|
|
Thanks in advance for reading this.
Let's say I have a file (file01) with this data in ASCII (ignore line col):
line01 123abc
line02 Header01 Starts blah var
line03 detail01 000001
line04 detail02 000002
line05 detail03 000003
line06 detail04 000004
line07 detail05 000005
line08 detail06 000006
line09 detail07 000007
line10 Header01 Ends
line11 Header02 Starts blah var
line12 detail01 000001
line13 detail02 000002
line14 detail03 000003
line15 detail04 000004
line16 detail05 000005
line19 Header03 Ends
Here's what I need to do:
1. traverse each line and modify some section of the line
(it could postion 10-20) according to some logic in a function.
2. For Header line, I need to know the last detail line for that header
of a section (it could postion 20-25). So for Header02 (line11) I would
need to grab the value '000005' (line16).
The result for file01 will have it's line modified accordingly.
The main question is how can I traverse down line by line, and
when I get to the Header, somehow get the value of the last detail line
for that header, and continue the next line after the header which
is the first detail line.
I know you can do this in C by creating a dummy pointer to point
to the header and then traverse to the last detail line and return the
value. And then destroy the pointer.
I just don't know how to do this is .NET.
Thanks in advance for your replies!
|
|
|
|
|
Completed my password storage program and down to the part where I would like to write the listview data to an XML file (for later encryption).
Cannot find anything that gives me an nice or usable example on how to do this using the listview control. Does anyone have example code for this or a place I can be directed to for more research?
Thanks, everyone.
- Harold
|
|
|
|
|
I used this artical and it was great.
http://www.knowdotnet.com/articles/serializationoflistviewtoxml.html
Good luck...
When people make you see red, be thankful your not colour blind.
|
|
|
|
|
I saw that one and also found this article from the same author as well:
http://www.knowdotnet.com/articles/serializelistview-listbox.html
I can follow the code, but cannot get it working. I was hoping to find a working sample program that uses that or very simialr code to better understand how it works as well.
|
|
|
|
|
Hi,
By the looks of it creating a folder and password protect it seems a rare find. What I am trying to do is to create folders through VB.NET one for each person on a separate server drive and have it password protected. I have a database and I managed to create a folder for each record with a name found in Column1.
But now I need to set a password through code and possibly link it to column2.
Is this possible guys. I know there is the FileSystemWatcher and NotifyFilter but I dont know how to use them or if they will do the trick. Anyone has any idea please??
|
|
|
|
|
wrote: By the looks of it creating a folder and password protect it seems a rare find.
There's a reason for that. It "mostly" cannot be done. It kind of can, Microsoft released a free product to do that a while back, and 3 days later pulled it.
wrote: one for each person on a separate server drive and have it password protected
Imagine the total chaos if a person created 10 different folders, password protected them all with different passwords, and then called you to reset that password when they forgot them.
wrote: But now I need to set a password through code and possibly link it to column2.
Not possible since NTFS doesn't support this.
wrote: FileSystemWatcher and NotifyFilter
Has nothing to do with security of this kind.
Basically what you want to do isn't possible, for administrative reasons at the least. How it's properly done is to create a folder on the server, then assign the appropriate permissions for that users account to that folder and making sure noone else (except admins of course) have permission to that folder.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
okay David many thanks for your professional reply.
Our problem is that in our organisation we need to allocate one folder for each user. Now if the password protection isnt possible maybe there is another solution1. I was doing a search on the internet for this pssoibility and seems workable. It is this:
Create folders on server. Folder name will be the same as login name on the network. On user login his Folder will be visible on the desktop and he can store his files and subfolders in it. He will not have access to the Server and all folders created on it will be hidden. Only on boot up individual folder will be set to Normal for its user. On logging the folder will be sent to the server and marked as hidden.
Now I guess this involves Windows Services on which I have little experience. Can you see this solution feasible please?? Im kind of new in VB.NET windows manipulations so everything is a help.
cheers!
|
|
|
|
|
Doesn't windows already do this kind of thing when you setup remote profiles within a network. Each user has their own profile and when a user logs on Windows selects the correct profile across the network giving the user access to their own folder(s), drive mappings and so on, but locking out other folders. These folders can be mapped to things like "My Documents" and so on.
Unfortunately I don't really know the details about how to set that up, you are best asking a network administrator for help with that one.
|
|
|
|
|
focusit wrote: Create folders on server. Folder name will be the same as login name on the network.
So far so good. It's usually done under a shared folder on the server called, oddly enough, Home . The permissions on this folder are stripped for the Domain Users. On each individual folder under home, the folder inherits the permissions from its parent folder, meaning that noone (except an Admin) has permissions to any of the folders under home. For each individual folder under Home, you reinstate the permissions for that folders particular owner. This way, they can see their own home directory, but no others.
In your login script, you map a drive letter to the users Home\folder. Done, problem solved.
focusit wrote: On user login his Folder will be visible on the desktop
Usually not. Unless your login script, or something else, specifically creates a shortcut on the Desktop for the user.
focusit wrote: He will not have access to the Server
Unless you give the users permissions to other folder on the server and possibly map some drive letters for those areas.
focusit wrote: Only on boot up individual folder will be set to Normal for its user. On logging the folder will be sent to the server and marked as hidden.
You don't have to do any of this. You mark anything hidden or visible, ever. It turns into a administrative nightmare if you do.
focusit wrote: Now I guess this involves Windows Services on which I have little experience.
No, it doesn't. It's strickly Windows Networking. I suggest picking up a book on it before you even attempt to continue this. Anything you do in code is just going to needlessly complicate your situation.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi Dave,
Many thanks for your reply. Right so the folder handling system I will leave that to the network manager.
Now we very often have 2 people working together on a file on the same PC logging naturally with one username. I have created an application to transfer the file to the other person's folder. It works fine on my computer. Now will this application still be possible if I change the path to the server with all the domain and permissions you suggested. I am only selecting a file with the Showdialogu Window and copying a file to the other person's folder. Is this possible?
Cheers
|
|
|
|
|
No, scince each user is the only person who has access to their own home folder. This CAN change if the user grants the other some rights to the folder, or creates a sub-folder and grants the other user rights to it.
The usual way around this is a shared folder that everyone has access to. They can create their own folders in there and collaborate using the files stored in that.
But that's also something you have to setup with your LAN Admin.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I am writing an application that needs lots of things dynamically created, Labels etc.
Here is the code I use to add a label to the form:
Dim lblTitle as label
With lblTitle
.Left = 24
.Top = 24
.Width = 632
.Height = 48
.BackColor = Color.Black
.ForeColor = Color.White
.Font = New Font("Arial", fontsize, FontStyle.Regular)
.Enabled = True
.Text = "Title of the song"
.AutoSize = False
End With
controls.add(lblTitle)
I want to make a scrolling label, so I need to create a panel on the form, then create a label in the panel with a width wider than the panel width, and move the .left of the label to make it look as if it is scrolling.
I can do this when dropping the items onto a form normally, but not by dynamically creating them, please can someone help, I have been trying for days.
Thanks
|
|
|
|
|
You didn't create an instance of the label. Change your first line to this:
Dim lblTitle As New Label
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Sorry, I did use: Dim lblTitle As New Label,
Bu, my question is, how to dynamically create a panel with a Label in it.
|
|
|
|
|
Create the panel using the same method, add it to the Controls collection of the form. Create the label the way you're doing it now but add it to the Controls collection of the Panel, not the form.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Excellent.
I used:
'panel1.controls.add(txtTitle)'
and it worked fine.
Thanks again
|
|
|
|
|
Set the parent property of the label to the panel you create. Set the parent property of the panel to the form on which you want it to appear. The labels location coordinates will be relative to the top left corner of the panel. If you want the panel to show on the form you must set its visibility property to true and call BringToFront. You must do the same for the label so it shows on the panel.
|
|
|
|
|
I am trying to write a DVD player in VB.net
I have used the WMP SDK and embedded WMP in a VB application. I can open an mpg file, avi etc, but when I load a dvd 'VIDEO_TS.ifo' file into the embeded WMP it plays, but without sound.
Here is the code I use to load the DVD into WMP:
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName <> Nothing Then
file = OpenFileDialog1.FileName
AxWindowsMediaPlayer1.URL = file
End If
As I said before, the sound is heard, but no video is shown.
|
|
|
|
|
Does it play just using Windows Media Player?? Don't use your application to try and play it, just launch WMP.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|