1 Followers
26 Following
donnaexpert20

donnaexpert20

SPOILER ALERT!

In C#, immediately after the datagridview is bound towards the sql information supply, ways to adjust the information through the manage and automatically write back and update for the quantity...txt

recover partition table windows 've been detouring prior to. recover partition table windows 10 c# own datagridview data binding wizard includes a easy function, which is, it could merely show a table within the database, however the issue is the fact that alterations to datagridview can not be written back to by a easy strategy. Database.
So what recover ntfs partition table have began to try is to add the strategy of sqlcommandbuilder for the dataGridView1_CellEndEdit occasion to update the dataadapter();
By means of actual use, I can not always stimulate this update action. Seeing that some friends on csdn found such a problem, I later believed of a compromise approach, that is certainly, adding a button control to handle the click event inside the space, but not Be prepared.
Ultimately, the cellvalidated occasion was discovered by accident, so the code was put in:
[csharp]viewplaincopy?privatevoiddataGridVies1_CellValidated(objectsender,DataGridViewCellEventArgse)SqlCommandBuildercb=newSqlCommandBuilder(sda);sda.Update(ds);
In this way, datagridview automatically displays the information of the information supply. By clicking the cell in datagridview with all the mouse, changes, additions, and deletions of rows is often automatically updated for the data supply. Rest awhile;
Attach the source code, I hope to assist good friends that have exactly the same problem:
[csharp]viewplaincopy?usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Types;usingSystem.Information.SqlClient;usingSystem.Globalization;usingSystem.IO;usingSystem .Information.OleDb;usingSystem.Runtime.InteropServices;namespacexlstosql1publicpartialclassForm2:FormpublicForm2()InitializeComponent();privatevoidForm2_Load(objectsender,EventArgse)con.ConnectionString=connectionstr;sda=newSqlDataAdapter('select*fromtable_user',con );//Define dataadaptersda.Fill(dsdataGridView1.DataSource=ds.Tables[0];//Complete the data binding, datagridview can display the data sourcestringconnectionstr='integratedsecurity=SSPI;InitialCatalog=****;DataSource= localhost;';//Initialization connection string SqlConnectioncon=newSqlConnection();//SqlDataAdaptersda=newSqlDataAdapter();//DataSetds=newDataSet();privatevoiddataGridView1_CellContentClick(objectsender,DataGridViewCellEventArgse)privatevoiddataGridView1_CellEndEdit(objectsender,DataGridViewCellEventArgse) The sda ​​update statement cannot be placed, privat evoidbutton1_Click(objectsender,EventArgse)privatevoiddataGridVies1_CellValidated(objectsender,DataGridViewCellEventArgse)SqlCommandBuildercb=newSqlCommandBuilder(sda);//This command automatically generates related new, deleted, and updated commandsda.Update(ds);//Update data source)