|
You also could use StringCollection in the System.Collections.Specialized namespace (or Collection(Of String) for that matter). I seem to recall MS don't like things to return Arrays (this might just apply to Fields, I can't remember which one FxCop complains about...) I suppose it depends what you intend to do with the data later, but I often find Collections can be more useful and easier to work with.
|
|
|
|
|
Hi all.
I have written a simple application in vb.net (2.0) that reads data from an excel sheet (previously stored in focus databases) and stores it into a sql server database. I am using typed datasets and table adapters to store the data. I have an "Import" button whose event handler does the following in turn.
1. connect to the excel sheet through an ole db conn
2. read the contents in a while loop using the executeReader() method
3. store the values in variables where necessary conversions and validations are performed.
4. call an insert method in the associated dataset tableAdapter that stores these processed values in the sql db.
This is all working as it should. Now I need to check for existing records before I import the values - Ignore completely if the value is found.
According to msdn, I should be able to use my tableAdapters update method by passing a dataSet/Table/Row(s). So this is how I tried to tackle it.
Legend:
lbf = my DataSet
lbf_COKEnCOLE = the Database table associated with lbf DataSet
GetRecordByIdDateLab = runs the following SQL Query on the data
SELECT *
FROM lbf_COKEnCOLE
WHERE (ORIGINATOR_ID = @ORIGINATOR_ID) AND (SMPL_DTE = @SMPL_DTE) AND (LAB_NUM = @LAB_NUM)
(The actual sql refers to all the columns by names instead of using *)
Dim tableadapter As New lbfTableAdapters.lbf_COKEnCOLETableAdapter
Dim dataTable As lbf.lbf_COKEnCOLEDataTable = Nothing
'check for existing record by using GetRecordByIdDateLab method
dataTable = tableadapter.GetRecordByIdDateLab(ORIGINATOR_ID, SMPL_DTE, LAB_NUM)
If Not dataTable Is Nothing Then
If dataTable.Rows.Count > 0 Then
If Not dataTable(0).ORIGINATOR_ID = Nothing Then
'Row = dataTable(0)
dataTable(0).TURN = TURN
dataTable(0).SMPL_ANALYS_HOUR = SMPL_ANALYS_HOUR
dataTable(0).SMPL_ANALYS_MIN = SMPL_ANALYS_MIN
dataTable(0).MOISTURE = MOISTURE
dataTable(0).S = S
dataTable(0).VM = VM
dataTable(0).ASH = ASH
dataTable(0).HARDNESS = HARDNESS
dataTable(0).STABILITY = STABILITY
dataTable(0).QRT_TUMBLE = TUMBLE_30M
dataTable(0).APTSPC_GRAV = APTSPC_GRAV
dataTable(0).FREE_SWL_I = FREE_SWL_I
dataTable(0).PULV8TH = PULV8TH
dataTable(0).QRT_PULV = QRT_PULV
dataTable(0).SCR_4 = SCR_4
dataTable(0).SCR_3 = SCR_3
dataTable(0).SCR_2 = SCR_2
dataTable(0).SCR_1NHALF = SCR_1NHALF
dataTable(0).SCR_1 = SCR_1
dataTable(0).SCR_3QRT = SCR_3QRT
dataTable(0).SCR_HALF = SCR_HALF
dataTable(0).SCR_38THS = SCR_38THS
dataTable(0).SCR_QRT = SCR_QRT
dataTable(0).QRT_PULV = QRT_PULV
dataTable(0).SCR_8TH = SCR_8TH
dataTable(0).SCR_20M = SCR_20M
dataTable(0).SCR_30M = SCR_30M
dataTable(0).SCR_50M = SCR_50M
dataTable(0).SCR_100M = SCR_100M
dataTable(0).SCR_PAN = SCR_PAN
dataTable(0).SCR_QRT_PLUS = SCR_QRT_PLUS
dataTable(0).SAMPL_LOC = SAMPL_LOC
tableadapter.Update(dataTable) '<<THIS IS WHERE IT CRASHES WITH "A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll
End If
'The following tableAdapter works perfectly whenever the condition is true (for new entries that is)
ElseIf dataTable.Rows.Count = 0 Then
tableadapter.InsertQuery(counter, ORIGINATOR_ID, SMPL_DTE, LAB_NUM, TURN, SMPL_ANALYS_HOUR, SMPL_ANALYS_MIN, _
MOIS_GRAV, MOISTURE, S, VM, ASH, HARDNESS, STABILITY, QRT_TUMBLE, TUMBLE_30M, APTSPC_GRAV, _
FREE_SWL_I, PULV8TH, QRT_PULV, SCR_4, SCR_3, SCR_2, SCR_1NHALF, SCR_1, SCR_3QRT, SCR_HALF, _
SCR_38THS, SCR_QRT, SCR_8TH, SCR_20M, SCR_30M, SCR_50M, SCR_100M, SCR_PAN, SCR_QRT_PLUS, SAMPL_LOC)
End If
End If
****************************************
More details:
I have DataTable under "Watch" and the value for it shows up as "dataTable has not been declared". This ofcourse is misleading because it is, plus intellisense picks it up where I'm updating the column values by referencing them with dataTable(0).columnName
I have been wondering if
dataTable = tableadapter.GetRecordByIdDateLab(ORIGINATOR_ID, SMPL_DTE, LAB_NUM)
does what its supposed to do, ie. return a dataTable with the matching record. I tried to recieve the data in a row but it only allowed it to be saved in a datatable instantiated in this manner. Furthermore, when I read the values read into the datatable, each column value shows up only as lbf_COKEnCOLE.column (something to this effect) in curly braces. Almost everything else thats returned, like index values and what not that I suppose is used to keep the schema of the table has errors in it.
Any suggestions and help would be greatly appreciated!! I am trying to avoid suddenly using command objects when I'm doing everything else through a data Access layer. lastly, I have read and reread this msdn page
http://msdn.microsoft.com/en-us/library/ms233819(VS.80).aspx
and am trying to do everything as shown here, obviously to no avail
All .net people out there, if you would help this awkward programmer, it would be greatly appreciated! Thanks
~Ghazanfar
|
|
|
|
|
You probably want to shorten some of the lines in your code, some of your sentances are being lost at the edge of the screen, and I can't really work out what your question is properly.
|
|
|
|
|
Hi I am developing one application in Visual Basic 6.0, in that application, I am opening pdf file and word file through my software using Web Browser control. I want to restrict the document in such a way that no body will copy the information.
Therefore I want to disable the Ctrl+C , Ctrl+V, Ctrl+X from Keyboard.
Please help me.
Ranjan
ranjan175@hotmail.com
biswaranjan_nanda@rediffmail.com
|
|
|
|
|
How is this different from your last post[^]? If someone wants to copy something bad enough they'll just take a screen capture.
|
|
|
|
|
I am sure you can disable copy for PDF, but not sure how. Search on google and you will find something on it.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
Hello!
I have a little problem....
When i get a print preview of any document how can i hide a small message box saying "Page 1 of 1 Document" befeore displaying print preview?
I dont want it....!
Could any body help me?
Thanks
colgateas900197
|
|
|
|
|
|
I have opened an image as a bitmap using GDI+. Before I save it I want to know if the image has transparency in it. That is; is there any pixels in the bitmap that has the transparent color. I have made a solution that looks like this:
Dim objImage As Drawing.Bitmap = Drawing.Image.FromFile("png_with_transparent_bg.png")
Dim booTransparentColorFound As Boolean = False
If Bitmap.IsAlphaPixelFormat(objImage.PixelFormat) Then
For y As Integer = 0 To objImage.Height - 1
If booTransparentColorFound Then Exit For
For x As Integer = 0 To objImage.Width - 1
Dim objColor As Drawing.Color = objImage.GetPixel(x, y)
If objColor.A = Color.Transparent.A And _
objColor.R = Color.Transparent.R And _
objColor.G = Color.Transparent.G And _
objColor.B = Color.Transparent.B _
Then
booTransparentColorFound = True
Exit For
End If
Next
Next
End If
The problem is that if the image is very big, and there is no transparent pixel in it (or a transparent pixel is located in the lower right corner), the routine is very slow. Is there some quicker way to determine if there is transparency in the image?
Thanks in advance.
...Allan, Denmark
|
|
|
|
|
You only need to check the alpha channel (objColor.A) to find out if the color is transparent.
You can use the LockBits and UnlockBits methods to get access to the pixel data, to circumvent the GetPixel method. In VB you need to use marshalling to copy the data into an array, though. If you would have used C#, you could use pointers to access the data directly.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
The Alpha channel is used by GDI+ ? The extra byte in a 32 bit image was ignored by GDI.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: The Alpha channel is used by GDI+ ?
Yes.
The third line of the posted code checks that the pixel format actually is one that has an alpha channel.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi,
Two more comments:
1.
you could check the most likely transparent pixels first, say the four corners.
that would lower the average time, but not help for non-transparant images.
2.
in debug mode, you should avoid calling objImage.Height and objImage.Width in the
for loops; call them once instead, and store the values locally.
in release mode, this will not make a performance difference.
|
|
|
|
|
Hi,
I am writing program VB.Net (using Visual studio 2005). In this program, I am using browser control to send request on the internet. In responce to the request, one PDF file gets opened in the browser automatically. I want to save this PDF file on the hard disk. To do this, I think my program should be able to read the downloaded file in response to my request. Is there any way by which I can do this.
Thanks in advance.
Regards,
Sunil
|
|
|
|
|
If you just want to download the PDF file use HttpWebRequest. Google it and you'll find some example code.
|
|
|
|
|
I am afraid I can not use it. Becuase I don't have to use only the URL. Following is the flow of my program.
1) My application open a web page in WebBrowser control after sending some URL , say www.xx.com (using Navigate method)
2) The opened web page(www.xx.com) has fields like Name, Address, SSN. My application fills this information in the browser window programatically and clicks on one link in the same web page (this is also programatically)
3) on clicking the link, the filled infomration gets submitted and at the server end(of www.xx.com) it processes entered name, address and SSN and generates one PDF file. This PDF file gets opened in my browser(webbrowser) window.
4) This opened PDF, I want to save on the hard disk programatically without having to click manually on the save icon of the embedded acrobat reader.
I am unable to achieve step 4.
|
|
|
|
|
I really need help with this. I have tried multiple solutions but have not found an answer. Also, time will soon be a factor because this project is due at the end of June. The problem is I need my program to display files in an organized fashion and open them. I've done this but I need to just display the file name while maintaining functionality. My attempts have always left the full path to the file intact. Please, I don't even need the code, just a description of the solution.
|
|
|
|
|
If you use the FileInfo object
<br />
FileInfo fiYourFile = new FileInfo("Path\To\File.txt");<br />
There's a list of properties. FullName and Name both contain the name of the file, FullName is the full name including the path to the file. Name is just the name of the fil including it's extension. Is this the answer you're looking for? Else I don't understand your question..
|
|
|
|
|
I have this part down so far. If I use the .name property then I get the output I am looking for but I don't get path to the file necessary to open it. I need a way to give a list item one value and display another. I'd rather not use XML or databases.
|
|
|
|
|
Can you provide more description of what you are looking to achieve?
Do you want entire path intact or not?
Best Regards,
Sam Xavier
www.componentone.com
|
|
|
|
|
The program I am creating is a jump drive organizer. It is supposed to be able to organize various file types into separate lists. from these lists the file needs to be able to be selected and opened. My problem is that I don't want to display the fullpath to the file but only the name while still being able to open the file. (So far i've been manipulating strings for such things as choosing a directory.) I need the value of an item to be different than what is displayed the the end user.
|
|
|
|
|
Could you not create your own class with your overloaded "ToString" function... e.g.:
Public Class MyFileName
Public FileName As String
Public Overrides Function ToString() As String
Return System.IO.Path.GetFileName(FileName)
End Function
End Class
Then, when you add one of these items to a listbox, it will only display the filename, however, when you access the object, you can use the Filename string:
MessageBox.Show(DirectCast(ListBox1.Items(0), MyFileName).FileName)
|
|
|
|
|
I've just began learning about the concepts of object oriented programming this year. (second year of taking the comp. sci. course). I can use built in classes but still get a little confused making my own. Thanks for the help.
|
|
|
|
|
Hi,
No problem. It is really a simple class, but very useful in this instance (assuming you are displaying the list of files in a listbox, and using vb.net!!!).
If you are still struggling, here is a bit of messy code that may show you a bit more. All you need to do is create a new form with one listbox called listbox1, and paste this code into your app.
Public Class MyFileNameClass
Public FileName As String
Public Overrides Function ToString() As String
Return System.IO.Path.GetFileName(FileName)
End Function
End Class
Private Sub AddItemsToListBox(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Me.ListBox1.Items.Clear()
For Each FileNameStr As String In IO.Directory.GetFiles("c:\")
Dim o As New MyFileNameClass
o.FileName = FileNameStr
Me.ListBox1.Items.Add(o)
Next
End Sub
Public Sub DisplayInfo(ByVal sender As Object, ByVal e As EventArgs) Handles ListBox1.Click
If ListBox1.SelectedIndices.Count > 0 Then
For Each i As Integer In ListBox1.SelectedIndices
Dim o As Object = ListBox1.Items(i)
If TypeOf o Is MyFileNameClass Then
MessageBox.Show(DirectCast(o, MyFileNameClass).FileName)
End If
Next
End If
End Sub
This code should populate the listbox with all the files in your c:\ folder, but only display the name. When you click on a file, a messagebox will pop up with the full path & filename. Nothing exciting, but I think it may get you closer to what you want to do.
|
|
|
|
|
thanks, you saved me hours of work.
|
|
|
|
|