Datagridview
To inyect a DataSource to a Datgridview to update it automatically
- Create your query to fetch the data
query = "SELECT id, signum as Signum, name as Name,
remote_IP as 'Remote IP', remote_port as 'Remote Port' " +
"FROM eterminal.rel_user_session where signum = '" + signum + "'";
- Create a MySqlDataAdapter, this object will update your datagridview
- The Second parameter is an active connection of type MySqlConnection
MySqlConnection mconnection = new MySqlConnection("Server=146.250.116.2; Database=MydB; Uid=User; Pwd=pwd2@");
MySqlDataAdapter adapter = new MySqlDataAdapter(query, connection.getActiveConnection());
- This help to create the proper commands to update, delete, add
MySqlCommandBuilder cb = new MySqlCommandBuilder(adapter);
- The DataSet is where the information is allocated and is used to fill the datagridview
- The adapater will perform all the changes
ds = new DataSet();
adapter.Fill(ds, "session");
- Assign the DataSet to fill the datagridview
datagridview.DataSource = ds.Tables[0];
- The last step is update the datageridview, in the event you want. Ex in a click button to save the chage you need to add
- you are indicating to the adapter that need to update all the changes
adapter.Update(ds, "session");
Comentarios
Publicar un comentario