Hi,
I am writing a windows app in .net 2003. I have a datagrid which gets
data from a storedprocedure . My question is how can I update the data
in the datagrid? I want to call another storedprocedure to update the
data in the datagrid.
Thanks in advance. 6 4679
Shil,
The datagrid reflects the data in a datasource, therefore you will have to
update that datasource.
(How you get that data is not so important, the stored procedure to get data
is the same as a text procedure in ADONET, the only difference is where it
is located.)
I hope this helps,
Cor
"shil" <jo******@gmail .com> schreef in bericht
news:11******** **************@ z34g2000cwc.goo glegroups.com.. . Hi,
I am writing a windows app in .net 2003. I have a datagrid which gets data from a storedprocedure . My question is how can I update the data in the datagrid? I want to call another storedprocedure to update the data in the datagrid.
Thanks in advance.
Hi Cor,
I created a save button on the same form where I have datagrid. Here is
the code on that button click I worte.
Private Sub Save_Click(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles Save.Click
Dim myDa1 As SqlDataAdapter
Dim myCmd As SqlCommand
myCmd = New SqlCommand("sp_ AP_Upd_Assigned Users", myConn)
myCmd.CommandTy pe = CommandType.Sto redProcedure
Dim paramUserID As SqlParameter = New SqlParameter("@ UserID",
SqlDbType.Small Int)
myCmd.Parameter s.Add(paramUser ID)
paramUserID.Val ue = dgAssignedUsers .Item(0, 12)
Dim paramEmail2 As SqlParameter = New SqlParameter("@ Email2",
SqlDbType.NVarC har, 50)
myCmd.Parameter s.Add(paramEmai l2)
paramEmail2.Val ue = dgAssignedUsers .Item(0, 7)
myCmd.ExecuteNo nQuery()
End Sub
This works fine for the first row since I hardcoded that. How can I
loop through all rows in the datagrid? For example in web forms
datagrid I can do
For i = 0 To dgAssignedUses. Items.Count-1
Next
How can I perform the same thing in windows datagrid?
Thanks.
Shil,
In a windowforms datagrid or datagridview should you forget to loop through
the rows of a datagrid. It are just the cells that represents the
datasource.
In a windowform you loop through the rows of your datasource which is mostly
a datatable or a dataview. (You have not the problem that your datasource is
in fact at the service side).
The looping is than the same let say a dataview
\\\
for i as integer = 0 to dv.count - 1
if dv(i)("myfield" ) = "whatever" then
'the action to be done
end if
next
///
I hope this gives an idea
Cor
"shil" <jo******@gmail .com> schreef in bericht
news:11******** **************@ i39g2000cwa.goo glegroups.com.. . Hi Cor,
I created a save button on the same form where I have datagrid. Here is the code on that button click I worte.
Private Sub Save_Click(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles Save.Click Dim myDa1 As SqlDataAdapter Dim myCmd As SqlCommand
myCmd = New SqlCommand("sp_ AP_Upd_Assigned Users", myConn) myCmd.CommandTy pe = CommandType.Sto redProcedure
Dim paramUserID As SqlParameter = New SqlParameter("@ UserID", SqlDbType.Small Int) myCmd.Parameter s.Add(paramUser ID) paramUserID.Val ue = dgAssignedUsers .Item(0, 12)
Dim paramEmail2 As SqlParameter = New SqlParameter("@ Email2", SqlDbType.NVarC har, 50) myCmd.Parameter s.Add(paramEmai l2) paramEmail2.Val ue = dgAssignedUsers .Item(0, 7)
myCmd.ExecuteNo nQuery() End Sub
This works fine for the first row since I hardcoded that. How can I loop through all rows in the datagrid? For example in web forms datagrid I can do
For i = 0 To dgAssignedUses. Items.Count-1
Next
How can I perform the same thing in windows datagrid?
Thanks.
Hi Shil,
You're doing it the wrong way, if you're trying to loop through the
cells of the Datagrid and manually update each item at the back-end.
Remember that the Datagrid just represents a visual view of the data
present in your DataTable or Dataset as the case might be.
Therefore, any changes made to the contents of the Datagrid are
automatically reflected in the contents of the Datatable or Dataset.
So, you're next task remains to update this information back to the
Database.
Hopefully the following will clear the doubt : (lines might break up)
DataGrid -----------------> DataSet / DataTable ---------> Database
(SQL Server)
(visual representation) (Logical representation) (Data store)
So, to update the Dataset back to the Database, just use the
SqlDataAdapter. Update(myDataSe t, "TableName" ) method.
If you plan to have a stored procedure run when updating the Database,
make sure that the UpdateCommand property of your SqlDataAdapter points
to command object which is the stored procedure.
Regards,
Cerebrus.
Cerebrus,
My select query into dataset is quering multiple tables. It is not
simple select. So when I call Update command of dataadapter, I get this
error "Additional information: Dynamic SQL generation is not supported
against multiple base tables." How do I update data of a datagrid which
has data from multiple tables?
Thanks.
Hi shil,
Yes, that is natural. Use your own Update SQL statement as the
UpdateCommand.
myDataAdapter.U pdateCommand.Co mmandText = "UPDATE Categories SET
Description='Ch eeses, Milk, Ice Cream' WHERE CategoryName='D airy
Products'"
Regards,
Cerebrus. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: PAUL EDWARDS |
last post by:
I have a windows form that is bound to a datatable. In VB6
I could just update the field contents and it would be
updated in the database, however if I update the text
property of the control from code it is 50% chance that
the update will make it back to the dataset. If I update
the dataset instead of the form, it does not show on the
form.
Is there a method that should be used?
|
by: Sabari |
last post by:
Hi,
I have a DataGrid in my application and i use inline editing to
add and update data.I also have a DropdownList in my edit command.When
i update the datagrid it works well with windows XP but it dosent
update the Dropdown value in windows 2003 that too after the 55th
row.One of the problem here is the client needs the datagrid to display
100 records per page.Hope someone can help me out.Thanks in advance
Thanks and Regards
Sabari.
|
by: D. Shane Fowlkes |
last post by:
I have a Datagrid which in theory, should allow you to edit and update the
records. I've stripped my test page down so that it's only attempting to
update one field - "description". Yet when I make the changes and click
Update, it reverts back to the old value. I'm stumped! I've also checked
the db table and it is infact not updating. I'm attempting to follow and
example right out of ASP.NET Unleashed but not having much luck. Any...
|
by: Jonathan Upright |
last post by:
Greetings to anyone who can help:
I'm using WebMatrix to make ASP.NET pages, and I chose the "Editable
DataGrid" at the project selector screen. As you may know, it defaults
to the Microsoft SQL database "pubs". I've followed the instructions in
the comments and also changed everything pertaining to SQL over to
OLEDB. (i.e. Changed SqlDbType. to OleDbType.) I also changed the
datafield names and variable names accordingly. The page...
|
by: Strahimir Antoljak |
last post by:
I bound a DataGrid to a table (I tried with a DataView too).
I removed the row from the table, and then inserted a new
row at the same row index. the table gets the row to the
right position, but the bound DataGrid does not pick up
and appends the inserted row at the bottom of the grid,
not the right position?!?
Any ideas how to make the DataGrid pick up the changes
done in the table - to show the inserted row at the right
position?
| |
by: jason |
last post by:
Hi, all
How can I update data (multiple rows, but not every rows) using dataset in
datagrid?
I mean is there any way I can let datagrid know which row(s)/column(s) has been
modified and update them at database?
Thanks.
|
by: Stephen Plotnick |
last post by:
I'm very new to VB.NET 2003
Here is what I have accomplished:
MainSelectForm - Selects an item
In a public class I pass a DataViewRow to
ItemInformation1 Form
ItemInformation2 Form
|
by: Patty05 |
last post by:
I have a datagrid on a form that update properly when form loads. When the program runs and I type in/add a new row in the datagrid, it does not save the changes. Any help would be greatly appreaciated. Thanks.
Code below:
Imports System.Data.OleDb
Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
|
by: shookim |
last post by:
I don't care how one suggests I do it, but I've been searching for days
on how to implement this concept. I'm trying to use some kind of grid
control (doesn't have to be a grid control, whatever works best) to
display a dropdown menu of fields populated from table tblInvoiceData.
This control also includes a textbox which the user can input a value.
These two columns are side by side and not in a vertical layout.
The user then clicks on...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |