|
Hello,
i am abeginer so how to start C#.
|
|
|
|
|
|
.NET Book Zero[^] is a great free introduction.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
hello guys...Recently I cam across a requirement in which I have to get the PK Key values back, of the inserted / updated rows. For example
<pre lang="c#">
try
{
connection.Open();
// no of rows affacted
int AffactedRows = command.ExecuteNonQuery("Some Insert Query Here", connection);
connection.Close();
MessageBox.Show(result.ToString() + " Row(s) Inserted");
}
catch(Exception ex)
{
connection.Close();
MessageBox.Show(ex.Message);
}
</pre>
Now you see <b>AffactedRows</b> contains the number of affected (or inserted) rows. Now how do I get IDs of these inserted rows? thnx for any help or pointers
|
|
|
|
|
This almost belongs in the database forum.
It is up to your some insert query to return the value generated by the identity field. Either as an out parameter or as the return value or the selected record just inserted.
I used stored procedures that return the inserted record using the SCOPE_IDENTITY()
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
For a single row insert you can do a multipart query, like
update MyTable insert (a, b, c) values (1, 'Two', 2012-01-03); select SCOPE_IDENTITY();
... and then ExecuteScalar will return the key value added for that row.
There is a way to get the values back from a bulk insert but I can't remember what it is (I was too lazy to write the logic behind a bulk insert/update save procedure and just do a one line query for each item to be saved, considering there were only 50 or so at most in the application this was for).
Edit: SCOPE_IDENTITY is the SQL Server version, if you're using another database then you'll have to use something else, but I think they all have an equivalent query you can run.
|
|
|
|
|
I suspect my mentor is attempting to reduce me to girlie tears. I am to take my basic multiplication code and restrict the number of characters a user can enter (in order to avoid an overload)
After searching stackoverflow and Google, I can only find tutorials for textboxes but not working with console applications...or am I simply dim (stop laughing).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace debprojectC
{
class Program
{
static void Main(string[] args)
{
int number1, number2;
Console.WriteLine("Please enter a number:");
number1 = Int32.Parse(Console.ReadLine());
Console.WriteLine("Please enter another number:");
number2 = Int32.Parse(Console.ReadLine());
int result;
result = number1 * number2;
Console.WriteLine("Multiplication:" + result.ToString());
Console.ReadKey();
}
}
}
Assistance please.
Deborah
|
|
|
|
|
Instead of using Console.ReadLine you are going to have to use Console.ReadKey. Something along the lines of this:-
string str = string.Empty;
while (str.Length <= 5)
{
char c = Console.ReadKey(true).KeyChar;
if (c == '\r')
{
break;
}
if (c == '\b')
{
if (str != string.Empty)
{
str = str.Substring(0, str.Length - 1);
Console.Write("\b \b");
}
}
int enteredValue;
if(Int32.TryParse(c.ToString(), out enteredValue))
{
Console.Write(c);
str += c;
}
}
Console.WriteLine();
Console.WriteLine("You entered " + str);
Console.ReadLine();
This checks if the char entered is numeric, it handles backspaces and it checks to see if the user pressed enter. I am sure you could alter this to work with your app.
Hope it helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Thank you so much. This helps a great deal.
|
|
|
|
|
Glad to help
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
An alternative way to avoid the overload is just to check that the parsing actually succeeded:
bool MultiplyFromConsole(){
int number1, number2;
string line1, line2;
Console.Write("Please enter a number: ");
line1 = Console.ReadLine();
Console.Write("Please enter a number: ");
line2 = Console.ReadLine();
if(!(int.TryParse(line1, out number1) && int.TryParse(line2, out number2))
return false;
Console.WriteLine("Multiplication: " + (number1 * number2));
return true;
}
|
|
|
|
|
Thank you. My mentor wants me to allow the user another chance if he/she enters a number that is too large or enters letters instead of number. This is quite a learning experience.
Thank you for your help.
Deborah
|
|
|
|
|
hi
how to paint lines on combo-box in difference colors ?
for example:
line1 - red
line2 - green
line3 - yellow
i need any c# code
thanks
|
|
|
|
|
Throw us a bone here. What technology?
|
|
|
|
|
on WinForm , FrameWork 3.5 , C#
thanks
|
|
|
|
|
ComboBox and ListBox offer the same technique for OwnerDrawn painting; you can find an example here[^].
|
|
|
|
|
- Set Combo's draw mode (property is called DrawMode or something similar) to OwnerDrawFixed.
- Write OnPaint handler that paints the current item's background, if you want that
... and uses a brush of the appropriate colour to paint the text. Use the Font property of the combo.
|
|
|
|
|
i want to learn .net i have no idea please help me out
|
|
|
|
|
Decide which language you want to use.
Download the free tool from Microsoft Visual Studio express
Locate a good book and start working through it.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I agree with Mycroft - a book or a training course are the best ways - if you just dive in and learn as you go you will miss far too much important stuff, or not understand the stuff you do learn.
Wrox do good books, as do Apress - just avoid anything with multiple exclamation marks or "in nnn days" in the title.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
VB6 for smarties in 11 months!!!!!
|
|
|
|
|
|
Hi!
For an application I have to learn, maintain and upgrade there is a code for installing Windows services. The code works on Windows XP, but it don't work on Windows 7 which I use.
The Windows service (Service.exe), needs two arguments for the main method. The two arguments are a string and a file path (File.txt).
This is the code for installing the service on XP:
string installutilFolder;
string filePath;
string serviceFolder;
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = installutilFolder + @"\installutil";
process.StartInfo.Arguments = @"/i /key=""" + filePath + "\" \"" + serviceFolder + "\\Service.exe \"" ;
process.Start();
Pretty simple only the assignment is a bit weird. Notice the installutil will have two arguments:
* The string containing the file path which is the argument for the service
* The service to install
I'm happy that this actually works on Windows XP. But when I run this code on Windows 7, the services seems not to be installed, because I cannot find it where all other installed services are in Windows.
Any solution for how to install the service for Window 7? A solution which is same for Window XP and Windows 7 would be best.
|
|
|
|
|
if installutil is any good, it will produce some output, maybe a log file, maybe some system events, telling you about success/failure with some detail. As it isn't a standard piece of software, nobody is going to be able to tell but you.
|
|
|
|