Jump to content
ragazzo04

Insert/update/delete a BD numa dataGridView

Recommended Posts

ragazzo04

Boa tarde pessoal

Precisava de uma ajudinha, estou a fazer um projecto em C# com uma BD em mwsql e queria saber se é possivel e de que maneira se o for, guarda as alterações que são feitas directamente na GridView seja eles insert, update ou delete.

capturarfm.png

A informação é carregada por exemplo pelo botão "Mostra Tudo" através do código

           string cnn = "server = localhost ; user id = root ; pwd = 'root';database=gabineteinformatica";
	    MySqlConnection myConnection = new MySqlConnection(cnn);
	    MySqlCommand myCommand = myConnection.CreateCommand();
	    MySqlDataAdapter mAdapter;
	    DataSet mDataSet;
	    myConnection.Open();
	    mDataSet = new DataSet();
	    //cria um adapter utilizando a instrução SQL para aceder à tabela
	    mAdapter = new MySqlDataAdapter("SELECT * FROM tipo_local ORDER BY idTipo_local", cnn);
	    //preenche o dataset através do adapter
	    mAdapter.Fill(mDataSet, "tabela_dados");
	    //atribui o resultado à propriedade DataSource da dataGridView
	    dataGridViewLocal.DataSource = mDataSet;
	    dataGridViewLocal.DataMember = "tabela_dados";

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.