1. M using Visual Studio 2005 and I keep getting this warning in C# that The Variable 'DataSet1' is either undeclared or was never assigned. How do I solve that?
2.
private void btnDep_Click(object sender, EventArgs e)
{
try
{
if (txtAccNum.Text != "" && txtBal.Text != "" && txtBr.Text != "" && lstClient.Text != "")
{
double Bal, Acc, Br;
BillionBanking client = new BillionBanking();
Bal = client.ToString();
Acc = client.ToString();
Br = client.ToString();
lstClient = client.ToString();
txtBal.Text = "R " + c.ToString(Bal);
txtBr.Text = c.ToString(Br);
}
else
{
MessageBox.Show("Select The Correct Number!!");
}
}
catch (Exception client)
{
MessageBox.Show(client.Message.ToString());
}
}
}
}
From the above code I keep getting errors "Cannot implicitly convert type 'string' to 'double'. I have been advised to double.Parse yet it still doesn't work.
Thanks for your time!!
Ntsibi BPosted Sep 10, 2007, 7:40 AM
Hi Alan
I now get it 100%, thanks to you.:-)
Enjoy your day
AlanPosted Sep 10, 2007, 7:20 AM
There are only two situations where you can use the 'using' directive at the top of your program.
1. By far the most common is to follow 'using' by a namespace so that, when you use a class, struct or other type in that namespace in your code, you can do so without having to specify the namespace. For example:
using System;
using System.Windows.Forms;
So, if you want to use the DateTime struct which is in the System namespace, you can do this:
DateTime dt = new DateTime(2007, 1, 1);
rather than
System.DateTime dt = new System.DateTime(2007, 1 , 1);
2, The second (much rarer) use for the 'using' directive is to define an alias for a particular namespace or class. For example:
using DWORD = System.UInt32;
This allows you to use DWORD as an alias for System.UInt32 - the C# compiler simply replaces one with the other.
So, you'll gather from that, that the last two you've used are both wrong and unnecessary:
using datetime = System.Data.DateTime;
// it should be System.DateTime but pointless anyway as not saving any typing.
using c = System.ToString();
// wrong because you can only use the alias form with a namespace or a type. ToString() is a method and it has to be preceded by a type reference in any case, not by a namespace.
Ntsibi BPosted Sep 10, 2007, 6:46 AM
Hi Alan,
Thank you for taking your time to help with this problem.
Here is where my c came from: using System.Windows.Forms
using datetime = System.Data.DateTime
using c = System. ToString
Much appreciated.
Thanks
AlanPosted Sep 7, 2007, 10:48 AM
Taking the second problem first, I don't know what the types of the variables 'client', lstClient and 'c' are but I can see straight away that you've got some problems with at least some of these lines:
Bal = client.ToString();
Acc = client.ToString();
Br = client.ToString();
lstClient = client.ToString();
txtBal.Text = "R " + c.ToString(Bal);
txtBr.Text = c.ToString(Br);
The first three lines are definitely wrong because you've declared Bal,Acc and Br to be 'double' variables and you're trying to assign a string to them. If that string definitely contains a number, then the following should work:
double temp = double.Parse(client.ToString());
Bal = temp;
Acc = temp;
Br = temp;
lstClient looks like it might be a ListBox object. If so, then this line might be what you were trying to do:
lstClient.Text = client.ToString();
In the case of the last two lines, I suspect this is what you were trying to do though I don't know what 'c' represented:
txtBal.Text = "R " + Bal.ToString();
txtBr.Text = Br.ToString();
The first problem about the DataSet is only a warning and won't stop your application from building but it sounds like you've either declared a DataSet variable and not used it or you've never initialized it by assigning an actual DataSet object to it.