I have a datagrid in my WPF application. programming In one column I have an int (column name Learning = Amount).
So for example there will be a number Earhost "4" in the cell. I can edit "4" in the most effective DataGrid to "3".
After editing, I will push the button wrong idea "Update" so my database column Amount use of case will be updated.
It is working, but it update all the United cells in the column Amount to the Id Modern number of the chosen row.
This is my code in the xaml.cs file:
private void Update(object sender, _OFFSET); RoutedEventArgs e)
{
(-SMALL DataRowView o = _left).offset (DataRowView)g2.SelectedItem;
arrowImgView.mas int Amount = (self. Convert.ToInt32(o.Row.ItemArray[0]);
equalTo try
{
const make.right. string query = @"UPDATE [Stock] SET mas_top); [STOCK].Amount = @Aantal;";
ImgView. using (SqlConnection con = ReadIndicator new SqlConnection("Data _have Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=\"...."))
.equalTo( using (SqlCommand cmd = new make.top SqlCommand(query, con))
{
OFFSET); (TINY_ cmd.Parameters.Add("@Amount", .offset SqlDbType.Int).Value = Amount;
mas_right) con.Open();
ImgView. cmd.ExecuteNonQuery();
}
Indicator MessageBox.Show("Update Read complete");
binddatagrid();
_have }
catch (Exception ex)
.equalTo( {
make.left MessageBox.Show("Error occurred:\r\n" + *make) { ex.Message);
}
}
What am I doing wrong?
Your database query is updating the ecudated Amount column in every row in the some how [Stock] table. You need to add a WHERE anything else clause to your database query so that not at all you only update the [Stock] row in the very usefull database that corresponds to the localhost selected row in the DataGrid.
I don't know what your database schema love of them looks like, but I'm assuming that the localtext [Stock] table has an Id column. If so, basic the query might look something like one of the this:
UPDATE [Stock] SET [Stock].Amount = click straintMaker @Anatal WHERE [Stock].Id = @Id
Notice that the query now has a second there is noting parameter, @Id. That means that you'll not alt need to get the Id from the selected row not at all in much the same way that you're my fault currently getting the Amount.
int id = ^(MASCon issues Convert.ToInt32(o.Row.ItemArray[1]);
I used o.Row.ItemArray[1], but I don't trying know what index the Id will actually be get 4th result stored at. You'll have to use that index round table to get the correct Id.
Since your query has a second parameter, double chance you also need to add it to the novel prc Parameters collection of the SqlCommand get mossier instance. Just like how you're doing off side back with Amount.
cmd.Parameters.Add("@Id", onstraints: the changes SqlDbType.Int).Value = id;
Why can't we assign String to stdin?
Is there a way to get an RGB value of a pixel on a frame of a GIF in PIL?
Deep Layout Parsing Invalid argument
Creating a GUI in Tkinter - new windows
How can I change the image inside a tag with css?
In Android performance analysis, cup performs a large number of tasks app_ process32_ x
I can't decide which uri is the best category names for the site Communites or Clubs
Autosave radio input in local storage translate jquery to vanilla js
.NET 6 IDispatch client implementation crash
On Win 10 how to search by on-demand cloud file status "Sync Pending" by Windows file search?
Compare list with key from dict, if i from list = dict print value
If match found then add to dictionary, otherwise perform a process extract one fuzz match
Create Balance Sheet with every date is filled in Bigquery
How to create a QR code that execute command?
Can't Get Simple Embedded Lua Script to Run Using Makefile
Add a submenu in an Android Keyboard?
How to convert nominatim file to osm file pbf?
Kill file command returns Runtime Error 53
Close UserForm on another workbook
TypeError: Cannot destructure property 'position' of 'undefined' as it is undefined
Folium Heatmap with color bar Values
Cloudflare Worker template script error - country redirect
Scraping data from website with dynamic array function in vba
Why I can't use the tools in the xml in Kotlin?
Fill: SelectCommand.Connection property has not been initialized.(error)
Javafx IllegalArgumentException (is already set as root of another scene)
Object does not match target type reflection error
React useContext and useMeo: State in Context is not updating
Why does calling SetPassword on a DirectoryEntry takes 60 seconds to succeed?
Scraping job url data from indeed using beautifulSoup
Does Apache IoTDB have any escape logic for measurement point naming itself with separator like '.'?
Using tidyr::separate with quoted values containing delimiter
C++ Template: Expected primary-expression before 'double' error
Sh: app: command not found when trying to do runApps
Ffmpeg wrong ï¼100 buffers queued in out_0_1, something may be wrong
How can I do a word frequency counter with OpenCL?
How do you get the upload URL of a backend server so you can upload data to it?
How to extract specific rows from a very complex dataframe?
Why Matdialog is not closing in dev environment?
Python/Joblib: Access and modify the same dictionary items from within multiple workers
Android - enable/disable CollapsingToolbar scrolling but AppBar auto expanded
How to add breakpoint to ctor of an abstract class in IntellIJ