Windows Develop Bookmark and Share   
 index > Windows Forms General > cannot convert from 'string' to 'AccountManagement.IAccount'
 

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:

Code Snippet

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, i am getting these two errors:

Code Snippet

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 Sad

Any help/info would be much appreciated. This is quite urgement, so im awaiting any response ...

Latheesan  Monday, May 14, 2007 9:22 PM

Hello,

Thanks for that useful piece of info, I fixed the problem by using this code:

IAccount account = new Account(tmpName, "");

doEditAccount(account);

and now its working exactly like how i wanted it Smile

Latheesan  Monday, May 14, 2007 10:13 PM

Hi Latheesan -

You are getting the compiler error because your method 'doEditAccount' takes a single parameter of type IAccount, but when you are invoking the method, you are supplying a string - which can't be implicitly converted to an IAccount object.

It looks like you are missing a step that creates an IAccount instance from the data that is pulled from the XmlDocument.

What classes in your systemimplement the IAccount interface?

mberseth  Monday, May 14, 2007 9:51 PM

Hello,

Thanks for that useful piece of info, I fixed the problem by using this code:

IAccount account = new Account(tmpName, "");

doEditAccount(account);

and now its working exactly like how i wanted it Smile

Latheesan  Monday, May 14, 2007 10:13 PM

You can use google to search for other answers

Custom Search

More Threads

• Creating an exe without using a Form
• forecolor for datetimepicker
• ToolStripMenuItem: Event fired off has no subscribers, ever??
• Loading Forms Using Reflection
• How to change trackbar value based on another trackbar's value?
• ComboBox Validation.
• How to get "if file size bigger than ??"
• listing files whose folder is in selected directory.
• Toolstrip and treeview
• Faders, Knobs , Dials, Buttons for visual studio 2008