c# - Question on updating/inserting a datatable in a dataset -
I have to open a connection to the SQL database and read the subset of a table and if it is present then update the record or if did not get. By updating trobial
SqlConnection conn = new SqlConnection (ConnectionStrings.PgenIntranet.SqlClientConnectionString); SqlDataAdapter Indicator = New SqlDataAdapter (); String sql = "SELECT * FROM BusinessApplications.tbl_WPI_Site_Indicators where year = '" + + year + "' and month = '" + month + "' and plant id =" + site. Id; Indicators. Selection Commands = New SQL Commands (SKL, Conn.); SqlCommandBuilder CB = New SqlCommandBuilder (Indicator); Indicators. Update = cb.GetUpdateCommand (); Dataset ds = new dataset (); Indicators. Filled (DS, "Indal"); Datatelle Inditable = Databables ["Indetail"]; // This argument is not working if (indebt. Raho.kount == 0) {indental. New Rau (); } Detrovert dr = indental. NERO (); /// To make sure how this work indtable [1] ["PlantId"] = site.ID; Dr. ["PlantID"] = Site.id;
Since I've used dataset / datatabase / datorov, but I think If you are close enough to remember me correctly, then you will need to create a new line object as you do here:
DataRow dr = indtable.NewRow ();
Then populate that data with your data, also how you were doing it:
dr ["PlantId"] = site .id; Finally
Then in the datatale add row collection to that row (you want to double check that if your datatable instance is actually datatable in the Tables collection on dataset, remember me special things Instead of referencing the Tables Collection, it may be safe to keep it directly in your context.)
Note that it adds the line not back to the database Land. It just adds to the DataTable example, you will have to update the database accordingly. And this setup is something that's here ... messy ... so I do not have a quick reply to it. Since you are just using plain old ADO, I think that you will need to create an update command and populate it and run it against the connection.
In doing so, please have SQL injection vulnerabilities like you have one :)
Comments
Post a Comment