Product, version and build: Powershell Studio 2015 Version 4.2.85
(*** Please do not write "latest" as a version, specify a version number ***)
32 or 64 bit version of product: 64bit
Operating system: Windows 7 Enterprise
32 or 64 bit OS: 64bit
PowerShell Version: 4
DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM
Here is my problem: I'm building a Powershell application with a parent form and 3 other child forms, all of which communicate with a SQL Server 2014 db (local right now) as well as SCCM. The issue I'm having is when I'm trying to use a DataGridView as user input. I created 3 columns and it is successfully adding an extra row once I start entering data and it shows the data in the cells, but when my "Update" button is clicked, the whole app seems to freeze. I put a Breakpoint at the "buttonUpdate_Click Event, but when I try to Trace/Debug the script, it never goes to the buttonUpdate_Click event in the script. I know this might not be related to PS Studio, but I am at a loss as to how to Google this particular issue. I feel like a DataGridView is the best way to go since I don't know how many rows a user will enter in before sending the updated data to the db. In case anyone has a better solution to dynamically have users enter similar data into multiple rows, let me know.
Brian
Unable to get DataGridView to work as an input
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Unable to get DataGridView to work as an input
[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Unable to get DataGridView to work as an input
How are you doing the update. You cannot update a disconnected table. You must use a data adapter and update the table through the adapter. The table must have a primary key that is correct.
Re: Unable to get DataGridView to work as an input
This has nothing to do with updating a table. The issue is I felt, after seeing what it does, a DataGridView is perfect for my app since I don't know how many entries the user will make and I didn't want to limit them to a certain number of rows. The only data the user provides is the computer name, a date for when the PC was replaced and the initials of the tech who replaced it. That's the only data I need and I tried setting up a 3x10 panel of text fields, plus the column headers. That way I couldn't get to work right and I felt there was a better way. Once I saw what a DGV can do, I used it. I just can't find the right way to access the values of the cells, and I can't trace my script. I'm going to have to look at the Parent script and see if I missed something. I'll try and post my code later.
Re: Unable to get DataGridView to work as an input
You only need to add grid and add the columns you want. The user can input as many rows as they need. Why is this a problem? We do this all of the time.
What is your "Update" button? What does it so? To update a table from a grid you need to have a data adapter or you need to manually grab the new rows and insert them into the table.
See this for some idea of how data bound grids work: <attached>
What is your "Update" button? What does it so? To update a table from a grid you need to have a data adapter or you need to manually grab the new rows and insert them into the table.
See this for some idea of how data bound grids work: <attached>
- Attachments
-
- Demo-DGVUpdateTable.psf
- (13.42 KiB) Downloaded 159 times
Re: Unable to get DataGridView to work as an input
Unfortunately, the psf file won't open in my version of PS Studio. I'm curious to see how it works. If you change it to a ps1, I can look at it.
Re: Unable to get DataGridView to work as an input
I use Invoke-Sqlcmd to do my db queries, so I'm not sure how to convert your type of sqlcommands to something I can use in Invoke-Sqlcmd. I just can't figure out how to get data from the DataGridView.
Re: Unable to get DataGridView to work as an input
I posted no SQL commands. The code is designed to convert an object collection into a data table. The data table shows how we can insert records into the data table. Updates to SQL Server cannot be established through a table returned by Invoke-SqlCmd as it has no connection to the server and does not allow updates.
Attached is a file that shows how to create a data attached grid that can update a connected database table.
Attached is a file that shows how to create a data attached grid that can update a connected database table.
- Attachments
-
- Demo-DGVUpdateTable.ps1
- (6.17 KiB) Downloaded 146 times