|
hi Luc
1. yup, now i understand what u were trying to explain
2. sorry, i used wrong words.. my english is not so good.. I choose the
full path name C:\Documents and Settings\Desktop\FTP and
C:\Documents and Settings\Desktop\PORTAL
3. again, thank you for ur explaination..
4. That is why im confiused bcoz my friend run this code witth the
expected output, but mine didnt.. this is getting weird..
|
|
|
|
|
You're welcome.
If it fails, look at the intermediate values; maybe you have a typo somewhere.
|
|
|
|
|
yup.. there's sum thing wrong with the directory that i select.. it can run rite now thanks .. but another problem come out
actually i have to select files that must need to map drive 1st. but when i used this coding to select files in my computer, it cannot select the drive from portal and ftp that i has map already.. can u pls take a look at my coding?
Dim folderopen As New FolderBrowserDialog
With folderopen
.RootFolder = Environment.SpecialFolder.Desktop
.SelectedPath = "C:\DOCUMENT"
.Description = "Select the source directory"
If .ShowDialog = Windows.Forms.DialogResult.OK Then
' Display the selected folder if the user clicked on the OK button.
MessageBox.Show(.SelectedPath)
txtdir2.Text = .SelectedPath
End If
End With
|
|
|
|
|
Hi,
I'm not familiar with FolderBrowserDialog, but you seem to violate the following MSDN remark:
"If the SelectedPath property is set before showing the dialog box, the folder with this path will be the selected folder, as long as SelectedPath is set to an absolute path that is a subfolder of RootFolder (or more accurately, points to a subfolder of the shell namespace represented by RootFolder)."
C:\Document is not inside SpecialFolder.Desktop (which is located much deeper, its exact position
depends on you Windows version).
|
|
|
|
|
Hallo
I have a function for retrieving the last insertid from Mysql, now I have to change the program for sql server
For Mysql the function is :
Public Shared Function GetLastID() As Integer
Dim ID As Integer
Dim Cmd As New MySql.Data.MySqlClient.MySqlCommand()
Cmd.Connection = Connection
Cmd.CommandText = "SELECT LAST_INSERT_ID()"
Cmd.Connectie.Open()
ID = Cmd.ExecuteScalar
Cmd.Connectie.Close()
Return ID
End Function
For SQL server I have tried :
Public Shared Function GetLastID() As Integer
Dim ID As Integer
Dim Cmd As New System.Data.SqlClient.SqlCommand
Cmd.Connection = Connection
Cmd.CommandText = "SELECT @@IDENTITY"
Cmd.Connectie.Open()
ID = Cmd.ExecuteScalar
Cmd.Connectie.Close()
Return ID
End Function
It works for Mysql, but not for SQL, error : Conversion from type 'DBNull' to type 'Integer' is not valid.
Can anyone help please
|
|
|
|
|
@@IDENTITY is generally used in a stored procedure to get the id of the last inserted record. Selecting from the client is probably not valid, certainly if you are getting a null return.
Also there is no way of knowing what table you are getting the @@Identity for. Do some reading in BOL for more details.
To force a numeric try
Select Isull(@@IDENTITY,0)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Read the documentation[^] to know how @@IDENTITY works. It retruns the last identity value inserted for a specific session or NULL if nothing is available. In your code, you are opening a new connection to execute @@IDENTITY which will always return NULL .
As a workaround, you should execute this query before closing the connection which inserted the record. You will get the value then. It will be like,
Open connection
Execute insert statement
Execute the @@IDENTITY selection
Close the connection If you use stored procedures for insertion, the most obvious method is to add an output parameter to the SP and write the identity value to this parameter. You can read the value from parameter without querying database again.
Also be careful with @@IDENTITY as it may not return the identity value inserted into a specific table which you are expecting. This will behave differently when there are triggers written on the table. Check out @@SCOPE_IDENTITY also which is limited to a scope.
|
|
|
|
|
Don't know if this will be of any help as it is gathered from a stored procedure....
This is (part) of the stored procedure
......
,@NoteField
,@UDField1
,@UDField2
,@UDField3
,@UserName)
DECLARE @NewID int
SET @NewID = SCOPE_IDENTITY()
INSERT INTO [dbo].[CON_tbl_ContactPictures]
([ID]
,[ContPict])
VALUES
(@NewID
,NULL)
SELECT @NewID AS [ID]
I use SCOPE_IDENTITY to make an entry into another table, so to do that I need to make a variable.
When I have done that action the value is the returned to my VB code
'This is a brand new insert so we can get the Contact ID back from it.
dtblData = cDB.GetDataTableFromProc(listParams)
If Not dtblData Is Nothing Then
If dtblData.Rows.Count > 0 Then
Dim drowData As DataRow
drowData = dtblData.Rows(0)
ContactID = drowData("ID")
drowData = Nothing
Else
Please ignore the strange call to get the table and assume this is a normal Fill(DataTable). It would take too long to explain why I have to do it thsis way!!
The important part is the following code after that.
|
|
|
|
|
Um, just a thought. Try
Dim ID As Int32
...instead of Integer
Might work
|
|
|
|
|
I know I should know this, but I can't seem to remember. In Visual Basic, .Net, etc., how do you turn on/off the feature that gives you a list of available functions, methods, attributes, etc. within the text editor where you write your code? For instance, I have a text box named “txtPhoneNum”. When I type “txtPhoneNum.”, right after typing “.”, a list of valid, available items like “enabled”, “selected”, “value”, etc. are displayed where I can select what I want if this feature is on. I don’t know how this feature was turned off, but it would be a great help to get it turned back on. Thanks in advance for assistance.
|
|
|
|
|
Go to 'Tools' then 'Options' and in 'Text Editor' select your language,
or 'All Languages', and turn on the 'Auto list members' option.
|
|
|
|
|
Thanks for your reply. I tried what you wrote and it still doesn't work.
|
|
|
|
|
|
Hi,
I'm using datagridview in C# windows application and i have four datagridtextboxcolumn at designtime and my fifth column is datagridcomboboxcolumn which is added at run time. I want to pass some value ( number) as input to combo at run time, so that values in the combo are different for each row in the grid. I want to pass some number to the fifth combobox column so that combobox populates different values for each row in the grid. This is my scenario, can anyone help me with this with detailed explanation and C# code.
|
|
|
|
|
You might want to try the C# forum? You will probably get a more pertinent explanation than in this (VB) forum.
|
|
|
|
|
1. Wrong forum
2. You can bind the column and set the value member as desired.
The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures."
|
|
|
|
|
This is the code that calls the form where the file is displayed in a picture box.
<br />
frmCEA.ContactID = intContactID<br />
frmCEA.Text = "Edit a contact"<br />
frmCEA.ShowDialog()<br />
strAvatarToDelete = frmCEA.AvatarForDeletion<br />
frmCEA.Close()<br />
frmCEA.Dispose()<br />
<br />
If strAvatarToDelete.Trim > "" Then<br />
My.Computer.FileSystem.DeleteFile(strAvatarToDelete)<br />
End If<br />
I have tried on the form, and off the form like this, to delete an avatar but every time I get this message - even if I want to change photos.
The process cannot access the file 'C:\Documents and Settings\All Users\Application Data\.....\Avatars\AV000001' because it is being used by another process.
Any out there know why this might be??
|
|
|
|
|
Are there any other methods in your app using the file? If so, you need to cleanly end those resources so that the file is unlocked.
make sure the file is not readonly. Make sure you don't have other apps using the file.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Thanks for responding.
No nothing else is using the file. It just gets placed in the picture box:
Try
Me.PictureBox1.BackgroundImage = GetAvatar(ContactID)
Me.cmdDeleteImage.Enabled = True
Catch ex As Exception
Me.cmdDeleteImage.Enabled = False
End Try
Where GetAvatar =
Friend Function GetAvatar(ByVal ContactID As Integer) As Drawing.Image
Dim pict As Drawing.Image
'This just collects a file name
Dim strFilename As String = cDBHandler.ExtractContactImage(ContactID)
Try
If strFilename.Trim > "" Then
pict = Drawing.Image.FromFile(strFileName)
Else
pict = My.Resources.nouserpic_grey
End If
Catch ex As Exception
pict = My.Resources.nouserpic_grey
End Try
Return pict
End Function
Might it be because it ic alled in from another routine??
|
|
|
|
|
Well, if you rem out the logic in GetAvatar and loading it into the picture box, can you delete the file?
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Thanks for the suggestion Jon_Boy but unfortunately that would impact my code. I will give it a go if all else fails however.
|
|
|
|
|
Wasn't suggesting that as a perm. fix - just as a way for you now and in the future easily determine if and where your code was locking a file.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
TheComputerMan wrote: pict = Drawing.Image.FromFile(strFileName)
This locks the file. You need instead to create a new bitmap. open the file, copy the bitmap, and delete the original. At least, that's how I've got around this bug in GDI+ in the past.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I tried that Christian (using pict2 = pict.clone and then disposing pict) but still the same problem. It obviously carries the info accross to the clone.
Friend Function GetAvatar(ByVal ContactID As Integer) As Drawing.Bitmap
Dim pict As Drawing.Bitmap
Dim pict2 As Drawing.Bitmap
'This just gets the file name
Dim strFilename As String = cDBHandler.ExtractContactImage(ContactID)
Try
If strFilename.Trim > "" Then
pict = Drawing.Bitmap.FromFile(strFilename)
pict2 = pict.Clone()
pict.Dispose()
Else
pict2 = My.Resources.nouserpic_grey
End If
Catch ex As Exception
pict2 = My.Resources.nouserpic_grey
End Try
Return pict2
End Function
Looks like I might have to try storing the pic in the database, but I did not want to do that as it is only an SQL Server 2005 Compact so space limited.
Thanks anyway! (If you can think of any other way I would like to hear from you)
|
|
|
|
|
TheComputerMan wrote: pict2 = pict.Clone()
Christian is right, but you did not take his advise.
TheComputerMan wrote: Bitmap.FromFile(strFilename)
This is what keeps your file locked. Hence make and use a copy of the IMAGE and dispose of the original right away.
TheComputerMan wrote: any other way
No need. The one way is fine if executed properly.
|
|
|
|