Click here to Skip to main content
15,905,004 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am creating a database application in c# using sql. i am trying to search records in the database but i having an errors. the sql query i am using is:
Select * from Member where MemberId like @MemberId. this query works well in sql but when i used in my code in c#. this is my code:
C#
Members f = new Members();
            f.Show();
            string str = (@"Data Source=BROTHER-PC;Initial Catalog=iEMYS;Integrated Security=True");
            SqlConnection con = new SqlConnection(str);
            if (comboBox1.SelectedIndex == 0)
            {
                try
                {
                    string searchtext = textBox1.Text;
                    int value = int.Parse(textBox1.Text);
                   if (f.iEMYSDataSet2.Member.Count != 0)
                {
                f.memberTableAdapter.FillByMemberId(f.iEMYSDataSet2.Member, "%" + int.Parse(searchtext) + "%");
                }
            if (this.iEMYSDataSet.Administrator.Count == 0)
                {
                MessageBox.Show("No Administrator found in iEMYS System", "Admin Info");

                }
                }

                catch (Exception)
                {

                }
            }

I get this error:
the best overloaded method match for 'iEMYS.iEMYSDataset2TableAdapters.memberTableAdapter.FillByMemberId(iEMYS.iEMYSDataset2.memberDataTable,int)' has some invalid arguments

please I need help
Posted
Updated 19-Aug-14 3:50am
v2
Comments
[no name] 19-Aug-14 9:33am    
It's because you are taking a string, attempting to parse that string to an integer and then turning it back to a string by concatenating your integer to 2 other string and then trying to call a method that expects an integer.
MaximusDebois 19-Aug-14 9:42am    
so how do i solve the error
[no name] 19-Aug-14 9:46am    
Either pass the correct type of parameter to your method or change the method.

Then do yourself a favor and get yourself a decent book on basic programming and work through it. Reposting the same questions over and over is not going to help you. And, we can't teach you programming in a forum posting.

1 solution

Taking a string, converting it to an integer to call a method expecting an integer is one thing: but you can't then add strigns to it and expect it to remain an integer: what should I do with this?
%17% / 42

Mathematically, it's garbage - and that's what you are trying to pass to your method.

Either pass the integer value without adding strings to it, or write an overload fro your method which takes a string instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900