|
Hi,
is ExecuteReader() the right method to call, your query seems to produce only one number?
BTW: when a complex expression (such as the query string) is involved in a problem statement, I suggest you calculate the expression beforehand and print it out, e.g. using Console.WriteLine, to have a careful look at it (don't use Visual Studio's watch for this, it is confusing everyone with quotes and double quotes).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
thank you sir....actually i only want the value of the count.how can i get it in some variable.
|
|
|
|
|
Have a look at ExecuteScalar and ExecuteNonQuery; one of those should fit your purpose.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Replace
OleDbCommand cmd4 = new OleDbCommand("select count(*) from appointment where DOCTOR_NAME = '" + DropDownList1.SelectedItem + "' ";", con1);
with
<br />
OleDbCommand cmd4 = new OleDbCommand("select count(*) from appointment where DOCTOR_NAME = '" + DropDownList1.SelectedItem.Text + "'", con1);
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
its still not workin sir...
the error is
Line 173:
Line 174: OleDbCommand cmd4 = new OleDbCommand("select count(*) from appointment where DOCTOR_NAME = '" + DropDownList1.SelectedItem.Text + "' ", con1);
Line 175: dr = cmd4.ExecuteReader();
Line 176: //if (Convert.ToInt16(dr[0]) != 4)
Line 177: TextBox4.Text=dr[0].ToString();
|
|
|
|
|
Dear All, I have a shared assembly which i can access it from several application.
now i would like to make setup of all these application into a package.
can i bind or package my shared assembly with setup probject?
i am using simple wizard of vs2k5 to create setup project.
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
As long as you have included a reference to the assembly, it should be packaged and install correctly (to the application directory). Note that there re things you can do to stop this, so if the assembly you included do not install, then you have an incorrect setting somewhere.
Note that some common assemblies (e.g. the core .net framework ones such as System, System.Core) are installed into the Global Assembly Cache (GAC), and will not installed into the application folder.
Hope this answers your question!
|
|
|
|
|
thanks alot, infact i was afraid if the key for shared assembly can be installed with it (very funny).
thanks a lot.
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
Im not sure if i did the right thing to post here, i went through a few threads and i couldnt figure this thing out. sorry it's my first message, also im just learning c# and i have no idea wat error i have..
Should i post this somewhere else or create a message everytime?
This is my program:
using System;
class Work1
{
public static void Main()
{
int amount;
Console.WriteLine("Enter wage");
int wage = Console.ReadLine();
Console.WriteLine("Enter hours");
int hours = Console.ReadLine();
amount = (hours * wage);
Console.WriteLine("Amount = ", amount);
Console.ReadLine();
}
}
Im trying to learn c# and tried something very simple. wage*hours = my money. but of course i failed doing so.
Error 1 Cannot implicitly convert type 'string' to 'int' C:\Users\Saliba\Documents\Visual Studio 2008\Projects\Project2\Project2\Class1.cs 12 19 Project2
//refers to this line = int wage = Console.ReadLine();
Error 2 Cannot implicitly convert type 'string' to 'int' C:\Users\Saliba\Documents\Visual Studio 2008\Projects\Project2\Project2\Class1.cs 15 25 Project2
//refers to this line = int hours = Console.ReadLine();
those are the errors.
i know its pretty frustrating for admins and moderators to stay deleting/ moving posts. im sorry if this is the case.
thanks for future help, Luke
|
|
|
|
|
class Work1
{
public static void Main()
{
int amount;
Console.WriteLine("Enter wage");
int wage = int.Parse(Console.ReadLine());
Console.WriteLine("Enter hours");
int hours = int.Parse(Console.ReadLine());
amount = (hours * wage);
Console.WriteLine("Amount = {0}", amount);
Console.ReadLine();
}
}
|
|
|
|
|
Console.ReadLine() returns a string, which can't be automatically turned into an int. You'll need to use Int32.Parse() to do that (see msdn for more details and examples)
|
|
|
|
|
Hi,
welcome to CodeProject.
your post is OK, it is in the right place; no one is going to move or delete it, even when fully answered.
and neither should you, according to these guidelines[^]. The one thing you forgot to do is apply PRE tags to improve readability of your code snippet.
Your code shows two errors, you should take the error messages literally, they say "hey, here is a string and you want to treat it as an integer, I can't do that". And yes, that is what is going on as Console.ReadLine() returns a string, and you want to store it in an int.
This is a beginner's mistake; changing some type into some other type most often needs an explicit conversion; that could be either a cast (on inheritance up/downcasting), a call to a method of the Convert class (seldom really useful), or a call to a method of the destination's type class (most often).
So what you want here is int.Parse() with an explicit try-catch construct, or better yet int.TryPatse() Look those up in the MSDN documentation, make google your friend!
And if you aren't familiar with any of this, I strongly recommend buying and studying a book on C#. Here is
why[^].
Cheers.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
First of all just to let you know that console.ReadLine returns a string value so when it returns string value you can't directly assign it to and integer you should convert it to int
try
int x = Convert.toInt32(Console.ReadLine());
in console.WriteLine add the ".ToString()" so it would convert it to string so you could print it.
|
|
|
|
|
One more suggestion: tell your IDE to always show line numbers in editor windows; that way it is a lot easier to deal with compile-time and run-time errors. For Visual Studio look here[^].
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
As Luc said, you should probably use int.TryParse to check the input and convert the string input to an int.
You need some checking to deal with invalid input and re-request when necessary.
Console.WriteLine will automatically provide a string implementation of anything you supply by putting an index to it inside the string part in{} and placing the values as additional parameters.
Here's an ammended version of your code to explain by way of example:
int rate = 0;
int hours = 0;
while (rate == 0)
{
Console.Write("Enter rate: ");
if (!int.TryParse(Console.ReadLine(), out rate))
Console.WriteLine("Invalid input");
}
while (hours == 0)
{
Console.Write("Enter hours: ");
if (!int.TryParse(Console.ReadLine(), out hours))
Console.WriteLine("Invalid input");
}
int amount = (hours * rate);
Console.Clear();
Console.WriteLine("Rate = {0}, Hours = {1}{2}{2}Amount = {3}",
rate, hours, Environment.NewLine, amount);
Console.ReadLine();
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thanks all for the great help. I made a copy with all the different versions you briefed me with. I feel like this is a good start and I can make it with people like you. Thanks, really. ^^
|
|
|
|
|
Hi,
I have a function which returns a byte array. This method is being called in a loop. I need to build another byte array from these returned byte array.
For eg., in StringBuilder, we can keep appending string to it. Similar way, i need to append byte array to one main byte array.
How can this be achieved? Can anyone give me some solution here?
Thanks for your time.
|
|
|
|
|
byte[] byteArray1 = new byte[10];
byte[] byteArray2 = new byte[10];
List<byte> byteList = new List<byte>(byteArray1);
byteList.AddRange(byteArray2);
byte[] byteArrayAll = byteList.ToArray();
|
|
|
|
|
Thanks this worked fine
|
|
|
|
|
Create new byte array ,which length is the sum of the source arrays lengths and use System.Array.Copy to copy source data to the result array.
Life is a stage and we are all actors!
|
|
|
|
|
Once an array's size is declared, it cannot be changed so you can't append directly to the end.
If you know the end size you need then you can declare a new byte array, and use Buffer.BlockCopy to copy from other arrays into the new one specifying offsets where needed etc.
If the end size is unknown, I'd use a List<byte> and use the Add method to copy a byte or AddRange to copy other byte arrays into it, then call ToArray on the List<byte> at the end, and you will then have an array of the correct size.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I've been pondering on this a little more - these two methods may help. The first will append one or more individual items, the second one or more collections of items. These may not be the fatest, but they work.
public static T[] AddElements<T>(T[] currentArray, params T[] element)
{
T[] result = new T[currentArray.Length + element.Length];
Buffer.BlockCopy(currentArray, 0, result, 0, currentArray.Length);
for (int i = 0; i < element.Length; i++)
result[currentArray.Length + i] = element[i];
return result;
}
public static T[] AddElements<T>(T[] currentArray, params IEnumerable<T>[] elements)
{
List<T> resultList = new List<T>(currentArray);
foreach (IEnumerable<T> item in elements)
resultList.AddRange(item);
return resultList.ToArray();
} Some examples of useage:
byte[] currentArray = new byte[] { 0, 1, 2, 3, 4 };
byte elementA = 5;
byte elementB = 6;
byte elementC = 7;
currentArray = AddElements(currentArray, elementA);
currentArray = AddElements(currentArray, elementB, elementC);
byte[] elementsA = new byte[] { 8, 9, 10 };
byte[] elementsB = new byte[] { 11, 12, 13 };
List<byte> elementsC = new List<byte>() { 14, 15, 16 };
currentArray = AddElements(currentArray, elementsA);
currentArray = AddElements(currentArray, elementsB, elementsC);
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
modified on Wednesday, August 26, 2009 9:00 AM
|
|
|
|
|
Thanks for your reply
|
|
|
|
|
Hello
I need to view pictures of a file now this file has many pictures i need a way to access the first picture then navigate to the last one, the problem is that the images are not numeric named so i cant increment number to access the other image please help.
|
|
|
|
|
What have you tried?
What are they named?
Do you have an index of some sort?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|