3
Does anyone know why it gets like this?
It shows that using is not being used, but I do not understand why it is not recognized if I am using in the function below.
Resolution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Data;
namespace MySqlServerDemo
{
public partial class WebForm1 : Page
{
protected void Page_Load(object sender, EventArgs e)
{
BindData();
}
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();
}
}
}
what use function you are using?
– Marco Souza
These alerts appear because it is not good practice to keep calling libraries that you are not using in this scope. In declaring your class when inheriting class information Page, there is no need to inform all namespace there, you can just leave the name of the class as in the example below.
public partial class WebForm1 : Page
One way to correct these alerts is to right-click on the highlighted item and use the function Organize Usings -> Remove Unecessary Usings or use the shortcut CTRL + .– Leandro Araujo
@Marconciliosouza connect mysql daods database
– Lorena
@Leandroaraujo I did what I said and enabled only one using, I need to enable all, I started using the visual studio now, so I’m having these silly doubts.
– Lorena
if you remove Mysql.Data.Mysqlclient from the error?
– Marco Souza
gets the same mistakes
– Lorena
you who say ( not being used) for me this is no mistake.
– Marco Souza
@Marconciliosouza look at the image I posted now, gets those errors because using Mysql.Data.Mysqlclient is "disabled"
– Lorena
It’s not that, your system is in error.. what you can see right away is the declaration of the Bindata method, you forgot the () at the end. the right one would be
public void BindData() { ..... }
, edit your question with the code in if instead of the image so it is more readable.– Marco Souza
Okay, I’ll do that, thank you!
– Lorena
@Lorena seems to me that the declaration of its Binddata function is incorrect, try the following
public void BindData()
– Leandro Araujo
@Lorena if change line
MySqlCommand =cmd = new MySqlCommand()
ForMySqlComman cmd = new MySqlComman()
I believe it will work, and the same forMySqlAdapter
– Renan Carlos
@Renancarlos I went to realize that after, already I am, thank you very much!
– Lorena
Solved! Thank you very much, guys. @Marconciliosouza
– Lorena
@Renancarlos was worth it!
– Lorena
@Leandroaraujo was worth!
– Lorena