|
Yes, tell your teacher/professor to give you different homework, since that one
can be found everywhere on the web.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I have created an application in vb .NET using ODBCConnection Object (for MS-Access). this is a MDI Application. when i am running this Exe thru the network it is showing following error-
[Request for the permission of type 'System.Data.Odbc.OdbcPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
Error in SQL Connection
I Want to solve this problem thru code in 'VB .NET'. I do not want to do this manually as we do from "Control Panel->adminstrative tool->MS .NET Framework2.0 Configuration" How can i solve this problem. Please help me.
my mail ID is kkb_mda@yahoo.co.in
Thanks and Regards
Kishore
|
|
|
|
|
You asked this yesterday and were given the correct answer. You have NO CHOICE but to read up on and understand Code Access Security[^].
You're getting this exception because code executed from an non-local (read: network) source is NOT TRUSTED and runs in a heavily restricted sandbox. You have to tell the machines running the code to trust the source of the code to get more permissions.
|
|
|
|
|
Dear All im a newbie to scripting so please go easy on me.
Ive nearly finished my script but im stuck on the last points.
I need to append data in "Column A" created early in the script (groupmember.csv) with the data that is outputted by the password software last in the script, Currently its a .txt (newpasswords.txt) but could be a .csv.
Help please
thanks
paul
Option Explicit
Dim strCN, strFilter, objShell, strCmd, filePath
Dim oExcel, oSheet
' Prompt for group names and construct the filter.
strCN = ""
strFilter = "(|"
Do
strCN = InputBox("Enter Common Name of a group or Cancel", "Test")
If (strCN <> "") Then
strFilter = strFilter & "(memberOf=cn=" & strCN _
& ",ou=MYOU,dc=DOMAIN,dc=co,dc=uk)"
End If
Loop While strCN <> ""
strFilter = strFilter & ")"
' Use the WshShell object to run the csvde command.
If strFilter <> "(|)" Then
filePath = "d:\get-group\GroupMember.csv"
Set objShell = CreateObject("Wscript.Shell")
strCmd = "%comspec% /c csvde -f " & filePath & " -r """ & strFilter & """"
strCmd = strCmd & " -l givenName,userPrincipalName"
strCmd = strCmd & " -s SERVER.DOMAIN.co.UK"
objShell.Run strCmd, , True
'Deletes line 1 from GroupMember.csv
Const xlUp = -4162
Const xlLeft = -4131
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oExcel.Workbooks.Open filePath
Set oSheet = oExcel.ActiveWorkbook.Worksheets(1)
oSheet.Rows(1).Delete xlUp
'deletes Column A from GroupMember.csv
oSheet.Columns(1).Delete xlLeft
Dim c
For Each c In oSheet.UsedRange.Columns(1).Cells
c.Value = Left(LCase(c), 3)
Next
' saves the file
oExcel.DisplayAlerts = False
oExcel.ActiveWorkbook.SaveAs filePath
oExcel.ActiveWorkbook.Close
oExcel.Quit
Set oSheet = Nothing
Set oExcel = Nothing
End If
' send commandline parameters to Password Generator Professional
Set wshShell = WScript.CreateObject ("WSCript.shell")
wshShell.run """C:\Program Files\Kristanix\Password Generator Professional\PGP.exe"" /output ""d:\get-group\newpasswords.txt"" /format ""$p"" /quantity 1600 /showmsg /unique /mask ""{N:n,3,3}{N:s,1,1}""", 6, True
set wshshell = nothing
|
|
|
|
|
I always love when someone says that they're "nearly finished", but yet half their code still needs to be written...
To translate what I THINK you're trying to say, you want to read the passwords from a text file and put them in Column B of this Excel sheet??
Since it looks like you already know how to use the Excel object model, all you would need to do is use a FileSystemObject to open and read the passwords file, line by line, and put the password in the cell you're keeping track of, until you reach the end of the file.
|
|
|
|
|
Hi there Dave thank you so much for your reply.
(when i say nearly there ive only one more step to go on paper anyway !!!)
Sorry if my description was garbled
Yes i want to read the passwords from a text file.
But i want to add them INTO Col A (APPEND T0)
(Col A already contains info [First 3 chars of forename in LC] )
Column A will then be read by an app my developers are creating which will reset the users password to that in Col A.
Dave,
Im really feeling my way in the dark and have just been playing until i get somthing that works as im really new to scripting anything of consiquence.
Its the appending part that i suppose im really stuck on.
Many kind Regards
Paul
|
|
|
|
|
OK. Same thing, only instead of assigning the string read from the password file to column B, you're combining strings in column A.
Cell(row,col).Value = Call(row,col).Value & TextLineFromFile
|
|
|
|
|
Hi Dave,
Thanks for that.
Ive managed to cobble together some code which will copy from a .TXT to Col A of a .CSV.
Whereabouts\how would i addin your suggestion of:
Cell(row,col).Value = Call(row,col).Value & TextLineFromFile
Where you say (row,col)does that mean i need to specify the row and column..as ive a lot of row data to add.
Code below
-----------------------------------------------------------------------------
Const ForReading = 1
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oExcel.Workbooks.Add
i = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\passwords.txt", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
arrLine = Split(strLine, ",")
oExcel.Cells(i, 1).Value = arrLine(0)
i = i + 1
Loop
oExcel.ActiveWorkbook.SaveAs ("c:\newtest.csv")
objFile.Close
oExcel.Quit
-----------------------------------------------------------------------------
|
|
|
|
|
Sorry
Forgot to add that quite obviously Creates a new file not adding to an existing one....
Paul
|
|
|
|
|
I don't do Office interop so I can't give you the exact syntax, but this is the right idea. You just need to get the existing value of the cell then append the string you read from the file to it and assign the new value to the cell.
|
|
|
|
|
I have an Access DB with a list of members and attendance dates. I have brought the data in with a left join (I need all members regardless of attendance). I need help setting up the following - I would like to be able to choose a member name from a combobox drop down and upon selection populate a datagrid with their attendance information. I need to do two things: Retrieve only unique names from the table for the combobox (right now, every name can have multiple entries because of the attendance join) using some kind of filter, and at the same time when a record with attendance entries is selected remove the filter to populate the datagrid. Right now I am binding the comboxbox to a BindingSource. Could someone walk me through how I would go about this?
Thanks.
|
|
|
|
|
You should ask these questions in the database forum as your problems are SQL-related rather than VB.
Paul Marfleet
|
|
|
|
|
What do you mean? The import and all that is working fine, I just need to know how to filter the datatable for the combobox and at the same moment have it display unfiltered info for the datagrid. In other words, at this point the datatable would look something like this:
MemberID, MemberName AttendID AttendHistory
100,a,1, 12/1/2007
100,a,2, 6/1/2007
100,a,3, 7/1/2007
101,b,1,12/1/2007
101,b,2,1/1/2007
etc.
I need the combo box to only retrieve the unique MemberIDs for its datasource (which I think will require filtering) and once selected to retrieve all of the rows connected to that member (which I think will require removing the filter.
|
|
|
|
|
have the datagrid continue to be connected to the datatable.
for your combobox have it be connected to a dataview. first setup the dataview filtering out the records you want. just check the help or internet on how to use a dataview.
|
|
|
|
|
Thanks.. so you are saying that so long as the source of data (ie the datatable) is showing all of the information, when I move through the records, the filtered dataview and unfiltered datatable will be in sync?
|
|
|
|
|
Yeah, the import is working fine, but your database stucture is total garbage. You should have three tables. One with all the members in it, another with all the conferences in it and another table that joins the two with memberId's that tell which conferenceId's they attended.
Ask this in the SQL Forum, cause right now, your code isn't workable until the database behind gets fixed.
|
|
|
|
|
How can i simultaneously Iterate and modify a .NET Queue i am using the following code:
<code>
Dim q As Queue = New Queue
Sub LoadValues()
q.Enqueue("mystr1")
q.Enqueue("mystr2")
q.Enqueue("mystr3")
executeloop()
End Sub
Sub executeloop()
If q.Count > 0 Then
For Each str As String In q
'do something with str
q.Dequeue()
MsgBox(q.Count.ToString())
Exit For
Next
executeloop()
End If
End Sub
</code>
And how can i add items to the Queue while iterating should i use SyncLock because I'm working on a Multithreaded application, and also not sure about the performance need your suggestions...
AliAmjad (MCP)
|
|
|
|
|
You cannot modify the collection as your enumerating it. You can modify the objects IN the collection, but you cannot modify the size of the collection (Add, Delete) at all in a For/Each loop.
|
|
|
|
|
Then what should I use for this purpose. I want to add items to the queue and at the same time want to manipulate it. Should I use collection object. And what's wrong with the code given above i know i cannot modify it while iterating but then what should i do to achieve the objective. Thanks for your time man.
AliAmjad (MCP)
|
|
|
|
|
Why are you using a Queue?? A queue is a list of items that's organized and manipulated on a First-In, First-Out basis.
What's the purpose of this collection?? The type of collection you use isn't so much dictated by what it's going to hold, but how the collection is going to be used.
If you want to manipulate items, adding them and removing them, then a List(Of T) would work, an array of strings, ArrayList, ...
|
|
|
|
|
Actually I'm working on a Distributed Web Crawler a Multithreaded application where each URL discovered will going to be added in a queue to implement the breadth-first search model. Many threads will access this queue and get the URLs from the top and then add the newly discovered URLs at the end of the queue and them remove the carwled URLs from the queue. Now what should i use in such a scenario. but when i implemented this logic i get this error "Collection was modified; enumeration operation may not execute".
AliAmjad (MCP)
|
|
|
|
|
Why are you enumerating them?? I don't see anything in this description that would justify it.
Well, now I see where your code came from. It's a modification of the sample code on MSDN.
You don't need a loop to dequeue items. The Dequeue method pops the top item off the queue and returns it an as Object. You have to cast the Object back to a String in order to use it.
Dim url As String = DirectCast(que.Dequeue(), String)
|
|
|
|
|
OKKK i get it but as i am in a multithreaded application then lots of threads will access this queue then should i use SyncLock or what else to ensure thread safety.
AliAmjad (MCP)
|
|
|
|
|
Wrap the queue object in a class that implements adding and dequeuing. Use the SyncLock on an object to make it thread safe.
|
|
|
|
|
Cooool thanks buddy but I'm going to save MD5 hash algorithm of URLs in hexadecimal form in the Queue so which Queue(of T) i should use so that It'll consume as little memory as possible because I am gonna Enqueue it with lots of URLs. Again thanks for your valuable time Dave.
AliAmjad (MCP)
|
|
|
|