|
albean wrote:
I'm guessing that you are using an identity column.
Yes, that's how SQL converts Access's autonumber fields.
albean wrote:
If this is true then @@IDENTITY will give you the last identity inserted.
How do I use that?? I just barely know how to SELECT, INSERT, DELETE and UPDATE.
Thanks,
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
SELECT @@IDENTITY
If you created a stored procedure you could do this all in one fell swoop, however I would wait until you get more knowledge about SELECT, INSERT, UPDATE, and DELETE before looking into those.
If you have the budget I would highly recommend Wrox's SQL Server 2000 Programming for learning the in's and out's of, well, SQL Server 2000 programming [MSDE is SQL Server 2000 minus the GUI tools and some server optimizations]
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
|
I do what I can
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
I'll try that as soon as I have time.
James T. Johnson wrote:
I would highly recommend Wrox's SQL Server 2000 Programming
I will look into it, I'll order it through Amazon.
Thanks,
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
James T. Johnson wrote:
SELECT @@IDENTITY
How do I call it?? My table name is "Customers" and column name "ID_customer".
Looking at the docs in VS.NET I found it should be called like:
"SELECT @@IDENTITY AS 'Identity';"
But I just can't make it work. Do I use a OleDbDataReader and use Identity as column name?? or use ID_customer as column name?
Thanks in advance,
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
On the OleDbCommand object, use the ExecuteScalar method; it will return the first column of the first row, in this case it will return the value of @@IDENTITY which is the first (and only) column of the first (and only) row.
OleDbCommand cmd = new OleDbCommand("SELECT @@IDENTITY", myConnection);
conn.Open();
int identity = (int) cmd.ExecuteScalar();
conn.Close();
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
I called ExecuteScalar exactly like that and I get an "invalid cast" exception.
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
Here is an interesting question:
I have a form with a tab control with two tabs. If I create the dialog and add the tabs before displaying the form, everything comes ok. But sometimes, depending on the situation, only tab 1 is added before displaying the form.
The problem is when, because of a user action in tab 1, tab 2 must be shown also. Since there is no visible property or something like that for a tab, I create both tabs before showing the form, but only add tab 1. I pass a reference to both the tabs collection and tab 2 to tab 1 where they are stored as members. When such action is performed, I simply add tab 2 to the collection. Everything works as expected, except that all the controls in tab 2 appear very close to each other, using about half the available space.
Just in case it matters, I set the AutoScaleBaseSize property in the constructor of the form.
Any ideas?
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
Luis,
Que te paso?
If you send me your code I can maybe review it and help you out, I am not exactly sure what your problem is in your description.
Saludo,
Antonio
Soliant | email
"The whole of science is nothing more than a refinement of everyday thinking." -Albert E.
|
|
|
|
|
Hi Antonio,
The problem is basically that if I add the page before displaying the form, it shows correctly, with the controls perfectly arranged. If I add the page after the form is displayed, it comes up messed up (just that page, the other one (added before showing the form) is ok).
I can post some code tomorrow, I'm going to sleep now! (it's 2:27 am here)
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
|
Whoa! Thanks man. That's really cool.
David Stone
It seemed similar to someone saying, "Would you like to meet my knife collection?"
Ryan Johnston on Elaine's sig
|
|
|
|
|
|
Hi all
How does one do this? My compiler just complains
[DllImport("any.dll")]
static extern void Function(ref int icanbenull, ref int icanbenull2);
void AnyOldFunction()
{
int output = 0;
Function( ref output, null);
return output;
}
UPDATE:
After lotsa searching the haystack, I found a way to quiet the compiler, but the questions is, will this work? Will my int get treated as by ref or by value?
[DllImport("any.dll")]
static extern void Function(
[ MarshalAs( UnmanagedType.AsAny ), Out]object icanbenull,
[ MarshalAs( UnmanagedType.AsAny ), Out]object icanbenull2);
int AnyOldFunction()
{
int output = 0;
Function( output, null);
return output;
}
Unfortunately, I cant test this at the moment
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Did you try:
IntPtr.Zero
inplace of null?
C# won't let you pass null directly in this situation.
|
|
|
|
|
doesnt work.
From MSDN for IntPtr.Zero:
Remarks
The value of this field is not equivalent to a null reference
BTW the in the dll API, specify that either parameter can be an ref int (a value to retrieve) or null (value should not be retrieved).
Anyways once i get the other parts done, i'll try to see what results i get.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Did you try overloading the declaration?
[DllImport("any.dll")]
static extern void Function(ref int icanbenull, ref int icanbenull2);
[DllImport("any.dll")]
static extern void Function(ref int icanbenull, object icanbenull2);
[DllImport("any.dll")]
static extern void Function(object icanbenull, ref int icanbenull2);
[DllImport("any.dll")]
static extern void Function(object icanbenull, object icanbenull2);
int AnyOldFunction()
{
int output = 0;
Function( ref output, null);
return output;
}
|
|
|
|
|
Thanx , i thought of this too, but imagine having 5 parameters , then you will need 25 overloads. too much work for me .
I simplified the dll function in the 1st post.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
all i hade to do is put both the extern and calling function in an unsafe context and use the */& notation, no ref or out needed. Maybe I'm just not reading the C++ to well
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Hi, all. I posted this earlier, but it was a bit off topic in that thread.
Can anyone help me?
The question i have is, how does the conversion between a signed and an unsigned integer take place when the value is "out of bounds" ?
Eg.:
byte b = 200;
sbyte sb = (sbyte) b;
Console.WriteLine(sb);
I remember something from java and some c++ books about the "remainder" gets added starting from the minvalue. The sample would print -55 . UPDATE: i verified this with someone who knows this stuff. So howcome did they change a general intrepetation in .Net? Guess it has all todo with managed code and being CLS Compliant.
Is that correct? I cant seem to find any mention to this in MSDN.
I did find something about an OverflowException, but in my case, i pass the variable to an extern method (which seems to work as the same as my logic as explained above), or sending it as a MSG param via SendMessage.
Cheers
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
You might want to think about doing something like this:
Byte b = 200;
if(b < (int)SByte.MaxValue)
{
SByte sb = (SByte)b;
Console.WriteLine(sb);
}
else
{
Console.WriteLine("b is too large.");
}
Essentially you get caught in what I like to think of as a loop, but it isn't. When you go beyond the max (i.e. - MaxValue + 1; ) it will then wrap to the largest negative value. The -55 is correct, it is out of bounds and that's what it is trying to show you. I know you can do checked{...} and unchecked{...} blocks with certain data types which will allow you to control whether or not an exception is thrown, you may or may not be able to use this here.
HTH
Nick Parker
|
|
|
|
|
|
Section 6.2.1 of the C# spec covers this. Basically, the high bits are thrown away, and then the result is sign-extended to get the resultant value. I don't think you'd ever want to depend on this behavior, however.
You can trap such overflow by putting the code in a checked block:
checked
{
byte b = 200;
sbyte sb = (sbyte) b;
System.Console.WriteLine(sb);
}
|
|
|
|
|