|
Please read on how to ask good questions, 'please help me' is not a reasonable header. Everyone here wants help.
Which line gives the error ? As the word 'ImageFormat' does not appear in the code you pasted, I assume it's not one of these lines ? Have you tried using the debugger ?
This is what happens if you copy code off the web at random, articles and code snippets are great, but you need to take the time to understand them before you use them.
Christian Graus - Microsoft MVP - C++
"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 )
|
|
|
|
|
You have to import the namespaces that the code uses.
If you look up ImageFormat in the documentation, you see that it's in the System.Drawing.Imaging namespace.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
How do I get the id (primary key) of a row that I just insertyed into the database, so that I can insert the id into the foreign key of another table?
|
|
|
|
|
How are you inserting your data? What database are you using?
If you are using SQL Server stored procedures, it is very easy to get using a return parameter set to @@identity.
|
|
|
|
|
I am using the Tables object in SQL Server 2005 Express. I am not using the stored procedures object.
I am using the insert statements that are generated using the data source configuration wizard in Visual Basic 2005.
Is there a way to do it in VB.NET.
|
|
|
|
|
Probably. I use stored procs exclusively, so don't know much about the generated stuff. Microsoft examples tend to revolve around the generated stuff, so you could try MSDN?
|
|
|
|
|
The only reliable way to do it, is to write a stored proc that returns the identity that was just inserted, unless your DB only ever has one user at a time. Throw that auto generated rubbish out and try to write some code instead.
Christian Graus - Microsoft MVP - C++
"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 only reliable way to do it, is to write a stored proc that returns the identity that was just inserted, unless your DB only ever has one user at a time.
Actually, as long as you use the same database connection, it's perfectly safe to run the query "select scope_identity()" to get the latest generated id for that connection.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
IS that ID(primary key) an auto number?? If so you can get the max of that ID.
"Legacy code" often differs from its suggested alternative by actually working and scaling.
—Bjarne Stroustrup
|
|
|
|
|
It is an auto number. Do I just use a database query or is there another way?
|
|
|
|
|
You can use simple query : Select max(id) from table1
"Legacy code" often differs from its suggested alternative by actually working and scaling.
—Bjarne Stroustrup
|
|
|
|
|
There is another way. You can also write a trigger
"Legacy code" often differs from its suggested alternative by actually working and scaling.
—Bjarne Stroustrup
|
|
|
|
|
Yes, what you're being told will work, so long as there's never more than one user on the database at a time. Otherwise, it will not work properly.
Christian Graus - Microsoft MVP - C++
"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 )
|
|
|
|
|
Nilesh Hapse wrote: If so you can get the max of that ID.
No, never do that. That doesn't work if there are more than one user in the system.
There is an easier and perfectly safe method (posted elsewhere in this thread) to get the last generated id, so there is no reason to use this unsafe method to do it. Code tends to be reused, so unless there is a significantly simpler way of doing something under certain conditions, it's always better to use a way that works under any condition.
Methods like using max() to get the id is especially treacherous, as it seems to work perfectly fine as long as you are testing the system with a low number of users, but in the live system it will cause more and more errors when the load increases.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
And what about second suggestion to use trigger?? Is that safe?
"Legacy code" often differs from its suggested alternative by actually working and scaling.
—Bjarne Stroustrup
|
|
|
|
|
Yes, a trigger would be safe (provided of course that you write the trigger correctly).
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: Yes, a trigger would be safe (provided of course that you write the trigger correctly).
I thought about trigger after max . Not sure why?
"Legacy code" often differs from its suggested alternative by actually working and scaling.
—Bjarne Stroustrup
|
|
|
|
|
The scope_identity() function doesn't exist in some older versions of SQL, but in any version of SQL that supports it it is the easiest and most robust approach. It is guaranteed to work regardless of the number of clients accessing the database simultaneously. Approaches using max() or other such techniques can fail if, e.g., a client adds a record, then another client adds a record, then the first client queries max(). By contrast, if a client adds a record and later calls scope_identity(), it is guaranteed to return the last record added by that client even if other records have been added by other clients in the interim.
|
|
|
|
|
That depends on what database you are using.
For Access: "select @@identity"
For MS SQL: "select scope_identity()"
For MySQL: "select last_insert_id()"
You have to use this query on the same connection that you used to insert the record. This variable has database session scope, so it's safe even in a multi-user environment. Even if another user has added a record just after you did, you will still get the last id that was created using your database connection.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
i m using vb.net2005, and working on a project, i want to restrict the new user to register the software. so what is the code for main board registration or hard drive registration?
asif rafiq
|
|
|
|
|
WMI is what you want to look into, that's how you read all that sort of stuff.
Christian Graus - Microsoft MVP - C++
"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 )
|
|
|
|
|
hi,
first of all give reference to "System.management" in you application and import it in code window . After that use following code
dim objBaseBoard as ManagementObjectSearcher = New ManagementObjectSearcher("Select * From Win32_BaseBoard")<br />
<br />
For Each objMgmt In objBaseBoard.Get<br />
m_MotherBoardNumber = objMgmt("SerialNumber")<br />
Exit For<br />
Next
hope this helps
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
My Company
|
|
|
|
|
No manufacturer is required to expose this information at all, let alone do it through WMI.
You MIGHT get a serial number for the motherboard, you might not. Hard Drives are a bit more reliable, but there still isn't 100% exposure of the serial number by every manufacturer.
A more reliable method would be to pick information from a variety of sources and combine it in some way to form a more unique "fingerprint" of the hardware.
|
|
|
|
|
Hello friends,
I am developing a mdi application.
I have a form that takes input from user, and based on user selection , open a form as mdi child. i want the UserSelectionForm to stay on the top of all the other forms including MDI parent and any other mdi child forms until user has made any selection or cancelled the form.
any help?
:- Rashid Ali -:
modified on Tuesday, February 26, 2008 6:11 PM
|
|
|
|