cannot convert from 'string' to 'AccountManagement.IAccount'
-
Hi, I made a new form on my project that allows my user to search using specific search criteria. Once the record is found, i need to be able to open the Account Management form, so i have a code that looks like this:
private void doEditAccount(IAccount account) { AccountManageForm form = new AccountManageForm(account); form.ShowDialog(); } private void searchBtn1_Click(object sender, EventArgs e) { try { string fileName = "Account_Data.xml"; XPathDocument doc = new XPathDocument(fileName); XPathNavigator nav = doc.CreateNavigator(); XPathExpression expr; expr = nav.Compile("//Account[@ID='" + accountIDInput.Text + "']"); XPathNodeIterator iterator = nav.Select(expr); iterator = nav.Select(expr); if (iterator.MoveNext()) { XPathNavigator nav2 = iterator.Current.Clone(); string tmpAccID = (nav2.GetAttribute("ID", "")); nav2.MoveToFirstChild(); string tmpName = (nav2.Value); nav2.MoveToNext(); string tmpLastName = (nav2.Value); nav2.MoveToNext(); string tmpBalance = (nav2.Value); nav2.MoveToNext(); string tmpOverDraftLimit = (nav2.Value); nav2.MoveToNext(); string tmpFullAddress = (nav2.Value); doEditAccount(tmpName); this.Close(); } else { MessageBox.Show("Sorry, I could not find any account for\r\nAccount ID : " + accountIDInput.Text + "", "Friendly Bank"); } } catch (Exception ex) { MessageBox.Show("Error : " + ex.Message); } }
When i try to build the solution to test this out, im getting this following error(s):Error 1 - The best overloaded method match for 'FriendlyBank.AdvSearchForm.doEditAccount(AccountManagement.IAccount)' has some invalid arguments
Error 2 - cannot convert from 'string' to 'AccountManagement.IAccount'
Could someone help me out, where im i going wrong? the code looks right to me, but the compiler begs to differ :(
-
Hi, I made a new form on my project that allows my user to search using specific search criteria. Once the record is found, i need to be able to open the Account Management form, so i have a code that looks like this:
private void doEditAccount(IAccount account) { AccountManageForm form = new AccountManageForm(account); form.ShowDialog(); } private void searchBtn1_Click(object sender, EventArgs e) { try { string fileName = "Account_Data.xml"; XPathDocument doc = new XPathDocument(fileName); XPathNavigator nav = doc.CreateNavigator(); XPathExpression expr; expr = nav.Compile("//Account[@ID='" + accountIDInput.Text + "']"); XPathNodeIterator iterator = nav.Select(expr); iterator = nav.Select(expr); if (iterator.MoveNext()) { XPathNavigator nav2 = iterator.Current.Clone(); string tmpAccID = (nav2.GetAttribute("ID", "")); nav2.MoveToFirstChild(); string tmpName = (nav2.Value); nav2.MoveToNext(); string tmpLastName = (nav2.Value); nav2.MoveToNext(); string tmpBalance = (nav2.Value); nav2.MoveToNext(); string tmpOverDraftLimit = (nav2.Value); nav2.MoveToNext(); string tmpFullAddress = (nav2.Value); doEditAccount(tmpName); this.Close(); } else { MessageBox.Show("Sorry, I could not find any account for\r\nAccount ID : " + accountIDInput.Text + "", "Friendly Bank"); } } catch (Exception ex) { MessageBox.Show("Error : " + ex.Message); } }
When i try to build the solution to test this out, im getting this following error(s):Error 1 - The best overloaded method match for 'FriendlyBank.AdvSearchForm.doEditAccount(AccountManagement.IAccount)' has some invalid arguments
Error 2 - cannot convert from 'string' to 'AccountManagement.IAccount'
Could someone help me out, where im i going wrong? the code looks right to me, but the compiler begs to differ :(
Latheesan wrote:
Could someone help me out, where im i going wrong? the code looks right to me, but the compiler begs to differ
Latheesan wrote:
string tmpName = (nav2.Value);
tmpName is defined as a string.
Latheesan wrote:
private void doEditAccount(IAccount account)
The method doEditAccount requires as a paramters an object of a type that implements the IAccount interface, string does not implement that interface. You need to create the relevant object and pass that to the method.
Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
-
Hi, I made a new form on my project that allows my user to search using specific search criteria. Once the record is found, i need to be able to open the Account Management form, so i have a code that looks like this:
private void doEditAccount(IAccount account) { AccountManageForm form = new AccountManageForm(account); form.ShowDialog(); } private void searchBtn1_Click(object sender, EventArgs e) { try { string fileName = "Account_Data.xml"; XPathDocument doc = new XPathDocument(fileName); XPathNavigator nav = doc.CreateNavigator(); XPathExpression expr; expr = nav.Compile("//Account[@ID='" + accountIDInput.Text + "']"); XPathNodeIterator iterator = nav.Select(expr); iterator = nav.Select(expr); if (iterator.MoveNext()) { XPathNavigator nav2 = iterator.Current.Clone(); string tmpAccID = (nav2.GetAttribute("ID", "")); nav2.MoveToFirstChild(); string tmpName = (nav2.Value); nav2.MoveToNext(); string tmpLastName = (nav2.Value); nav2.MoveToNext(); string tmpBalance = (nav2.Value); nav2.MoveToNext(); string tmpOverDraftLimit = (nav2.Value); nav2.MoveToNext(); string tmpFullAddress = (nav2.Value); doEditAccount(tmpName); this.Close(); } else { MessageBox.Show("Sorry, I could not find any account for\r\nAccount ID : " + accountIDInput.Text + "", "Friendly Bank"); } } catch (Exception ex) { MessageBox.Show("Error : " + ex.Message); } }
When i try to build the solution to test this out, im getting this following error(s):Error 1 - The best overloaded method match for 'FriendlyBank.AdvSearchForm.doEditAccount(AccountManagement.IAccount)' has some invalid arguments
Error 2 - cannot convert from 'string' to 'AccountManagement.IAccount'
Could someone help me out, where im i going wrong? the code looks right to me, but the compiler begs to differ :(
In addition to what colin said, I assume your IAccount instance probably has a property that you can access to pass the information you're wanting to pass where a string is expected.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Latheesan wrote:
Could someone help me out, where im i going wrong? the code looks right to me, but the compiler begs to differ
Latheesan wrote:
string tmpName = (nav2.Value);
tmpName is defined as a string.
Latheesan wrote:
private void doEditAccount(IAccount account)
The method doEditAccount requires as a paramters an object of a type that implements the IAccount interface, string does not implement that interface. You need to create the relevant object and pass that to the method.
Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
Thank you very much for that prompt reply. I looked at my orignal code inside my MainForm which already had this doEditAccount method which is working fine, i could not see anything different from what i am trying to do on my search form. Have a quick look at the working code (if you have time) - http://nopaste.php-q.net/294607[^] The orignal working form does not need any parameter passed into the doEditAccount yet it works fine :s
-
Thank you very much for that prompt reply. I looked at my orignal code inside my MainForm which already had this doEditAccount method which is working fine, i could not see anything different from what i am trying to do on my search form. Have a quick look at the working code (if you have time) - http://nopaste.php-q.net/294607[^] The orignal working form does not need any parameter passed into the doEditAccount yet it works fine :s
I would guess this is what you are missing:
IAccount account = doFindAccount(nameTextBox.Text);
Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
-
I would guess this is what you are missing:
IAccount account = doFindAccount(nameTextBox.Text);
Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
Thanks for your reply again, i tried to put it in, but it said the doFindAccount method is not found. Even if i managed to get the method working, the problem is that, the doFindAccount searches for account in the hashtable. When im searching for the first time, this account name would not be in the hashtable. So, i looked at my main form and found this code that adds new account:
IAccount account = new Account(nameTextBox.Text, ""); account.SetAccNumber(nameTextBox.Text); doEditAccount(account); bank.AddAccount(account);
So, from that, i see, the code adds the account to the hashtable and then it does the editing part by opening the acc manage form. So, i tried to do this in my search form like this:IAccount account = new Account(tmpName, ""); doEditAccount(account); bank.AddAccount(account); this.Close();
Now the previous error is gone and have a new one:The name 'bank' does not exist in the current context
The AdvSearchForm is VERY similar to the MainForm, yet how can the form cannot find the instance 'bank' ?
-
In addition to what colin said, I assume your IAccount instance probably has a property that you can access to pass the information you're wanting to pass where a string is expected.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Thanks allot sir for your reply, but im a bit confused by what you said, since i've never programmed before till few months ago, im still getting used to using Visual Studio C# Express software and learning C# This is for my programming course (1st year) and it's alrady doing my head.
-
Thanks for your reply again, i tried to put it in, but it said the doFindAccount method is not found. Even if i managed to get the method working, the problem is that, the doFindAccount searches for account in the hashtable. When im searching for the first time, this account name would not be in the hashtable. So, i looked at my main form and found this code that adds new account:
IAccount account = new Account(nameTextBox.Text, ""); account.SetAccNumber(nameTextBox.Text); doEditAccount(account); bank.AddAccount(account);
So, from that, i see, the code adds the account to the hashtable and then it does the editing part by opening the acc manage form. So, i tried to do this in my search form like this:IAccount account = new Account(tmpName, ""); doEditAccount(account); bank.AddAccount(account); this.Close();
Now the previous error is gone and have a new one:The name 'bank' does not exist in the current context
The AdvSearchForm is VERY similar to the MainForm, yet how can the form cannot find the instance 'bank' ?
Latheesan wrote:
The AdvSearchForm is VERY similar to the MainForm, yet how can the form cannot find the instance 'bank' ?
Because bank is a field on the MainForm, not the form you are working on. The MainForm takes the bank as a parameter in the constructor and stored it in a field (sometimes known as a member variable). Perhaps you should do the same with this form.
Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
-
Latheesan wrote:
The AdvSearchForm is VERY similar to the MainForm, yet how can the form cannot find the instance 'bank' ?
Because bank is a field on the MainForm, not the form you are working on. The MainForm takes the bank as a parameter in the constructor and stored it in a field (sometimes known as a member variable). Perhaps you should do the same with this form.
Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
Great, brilliant suggestion. I added the following line towards the begining of the partial class:
IBank bank;
editted the search method like this:IAccount account = new Account(tmpName, ""); doEditAccount(account); bank.AddAccount(account)
And i was able to successfully build the solution. However, when i use the search form and enter an account ID and click search, it opens the account management form correctly, but when i close the account management form, i get this exception error message: http://i9.tinypic.com/4poqqab.png[^] -
Great, brilliant suggestion. I added the following line towards the begining of the partial class:
IBank bank;
editted the search method like this:IAccount account = new Account(tmpName, ""); doEditAccount(account); bank.AddAccount(account)
And i was able to successfully build the solution. However, when i use the search form and enter an account ID and click search, it opens the account management form correctly, but when i close the account management form, i get this exception error message: http://i9.tinypic.com/4poqqab.png[^]Nevermind, i fixed it by removing this line: bank.AddAccount(account); from the search method and it seems to be working. I know this is terrible, trial-and-error method is not a good way to learn new programming language, but im short on time. Im just glad its working and i can move onto the next piece of work.
-
Great, brilliant suggestion. I added the following line towards the begining of the partial class:
IBank bank;
editted the search method like this:IAccount account = new Account(tmpName, ""); doEditAccount(account); bank.AddAccount(account)
And i was able to successfully build the solution. However, when i use the search form and enter an account ID and click search, it opens the account management form correctly, but when i close the account management form, i get this exception error message: http://i9.tinypic.com/4poqqab.png[^]But you didn't pass a bank object to the form. Either do this in the constructor, or by setting up a property to receive it. The constructor option is usually preferable if it will always need it, or the object is mandatory.
Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
-
Thanks allot sir for your reply, but im a bit confused by what you said, since i've never programmed before till few months ago, im still getting used to using Visual Studio C# Express software and learning C# This is for my programming course (1st year) and it's alrady doing my head.
well, I'd recommend buying a book and working through it. We're glad to help ( you're asking us to help and trying to do it yourself, and that's never a problem ), but a trial and error approach isn't going to help you understand the core principles that you're struggling to grasp now. The main issues here as far as I can see: 1 - a variable has a type. If you try to pass an object of the wrong type, you're putting a square peg in a round hole. It's a 'thing', but it's not the right 'thing'. 2 - A class is an object designed to wrap specific functionalty. Once you define a class, you can have many instances of a class, just like knowing what a car is, I can own 3. If I have three cars, they are all independant objects, changing the tires on one car won't change the other ones. And, objects that exist within a class, are not visible outside that class, unless they are public, and then they need to be addressed via the class instance. If I want something that's in my car, I have to look inside the car, not on the ground. I hope that makes *some* sort of sense, but seriously, read through the texts you've been given, or consider buying a book. And, do some really basic to the point of useless projects that exist entirely to help you understand concepts like types and class scope.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
But you didn't pass a bank object to the form. Either do this in the constructor, or by setting up a property to receive it. The constructor option is usually preferable if it will always need it, or the object is mandatory.
Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website