using visual studio unnecessary

3

Does anyone know why it looks like this?

Resolution:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingMySql.Data.MySqlClient;usingSystem.Data;namespaceMySqlServerDemo{publicpartialclassWebForm1:Page{protectedvoidPage_Load(objectsender,EventArgse){BindData();}publicvoidBindData(){MySqlConnectioncon=newMySqlConnection("server=localhost;user    id=root;database=test");
            con.Open();

            MySqlCommand cmd = new MySqlCommand("select * from person", con);
            MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds);

            GridView1.DataSource = ds;
            GridView1.DataBind();
            cmd.Dispose();
            con.Close();
        }  
    }
}
    
asked by anonymous 15.02.2017 / 13:07

3 answers

5

Your problem is occurring due to the incorrect creation of the BindData method, at the end of your method you forgot the ().

See the correct statement.

public void BindData() 
{ 
     // seu código ... 
}

Compile (click the BuildSolution)yourprojectandcorrectanyerrorsthatappear,afterthereferencesthatarenotactuallyusedwillbeincolorlighter(almosttransparent)thesereferencescanberemovedwithoutproblemsfortheapplication,youcanremoveitonebyoneorusethebutton( ) to remove all unused reveries and sort out any remaining ones.

    
15.02.2017 / 13:37
1

Well, in addition to @MarconcilioSouza's response, there are more errors in your code.

Notice these lines:

MySqlCommand = cmd = new MySqlCommand("select * from person", con);
MySqlDataAdapter = adp = new MySqlDataAdapter(cmd);

The correct statement is:

MySqlCommand cmd = new MySqlCommand("select * from person", con);
MySqlDataAdapter adp = new MySqlDataAdapter(cmd);

That is, your% cos_de% method should look like this:

public void BindData()
{
    MySqlConnection con = new MySqlConnection("server=localhost;user    id=root;database=test");
    con.Open();

    MySqlCommand cmd = new MySqlCommand("select * from person", con);
    MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    adp.Fill(ds);

    GridView1.DataSource = ds;
    GridView1.DataBind();
    cmd.Dispose();
    con.Close();
 } 

Once these changes are made, I believe it will work normally. If you have any other questions, I'm happy to help.

    
15.02.2017 / 14:38
1

Complementing the answer, the clearest usings are not being used and can be removed.

Theoretically because if there is a syntax error, the VS precompiler can mark a particular line of using as not necessary when it is actually (after correction of the syntax).

It's a good practice to remove excess rows to keep the code cleaner.

    
15.02.2017 / 14:39