473,668 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Grid ?

Hi all,

I have created a simple database table in ACCESS named as "Users" that
contains only two fields "UserID" ( Primary key )and "Password". I am
having problems while UPDATING the records in DataGrid. When i click
Edit button in datagrid and edit my values it actually doesn't update
the vales with newly entered values rather it keep on showing the
previous records. following is the code I used to create datagrid
--------------------------------
<asp:DataGrid id="DataGrid1" runat="server" OnEditCommand=" DoItemEdit"
DataKeyField="U serID" AutoGenerateCol umns="false"
onUpdateCommand ="DoItemUpda te" CellPadding="2" >
<COLUMNS>
<asp:EditComman dColumn HeaderText="Edi t"
EditText="Edit" ButtonType="Lin kButton" CancelText="Can cel"
UpdateText="Upd ate"></asp:EditCommand Column>
<asp:BoundColum n HeaderText="Use r Name"
DataField="User ID" ></asp:BoundColumn >
<asp:BoundColum n HeaderText="Pas sword"
DataField="Pass word" ></asp:BoundColumn >
</COLUMNS>
</asp:DataGrid>
------------------------------------

and following are my Edit and update methods in Vb.net

Sub DoItemUpdate(ob jSource as Object, objArgs as
DataGridCommand EventArgs)
Dim username as TextBox
Dim password as TextBox

Dim u,pass,userid as string

username=objArg s.Item.Cells(1) .Controls(0)
u = username.Text

password=objArg s.Item.Cells(2) .Controls(0)
pass=password.T ext
Label2.Text=u

userid= DataGrid1.DataK eys(objArgs.Ite m.ItemIndex)
Label1.text =pass

'"UPDATE [Users] SET [UserID]=@UserID, [Password]=@Password WHERE
([Users].[UserID]"& _
'" = @UserID)"
Dim sql as String="UPDATE [Users] SET [UserID]='" & u & "',
[Password]='" & pass & _
"' WHERE [Users].[UserID]='"& userid &"'"
Dim connectionStrin g As String = "Provider=Micro soft.Jet.OLEDB. 4.0;
Ole DB Services=-4; Data Source=C:\Issue Tracker"& _
"\Access.md b"
Dim dbConnection As OleDbConnection = New
OleDbConnection (connectionStri ng)
Dim dbCommand As OleDbCommand = New OleDbCommand
dbCommand.Comma ndText = sql
dbCommand.Conne ction = dbConnection
dbConnection.Op en()

dbCommand.Execu teNonQuery()


dbConnection.Cl ose()

DataGrid1.EditI temIndex = -1
BindData()

end sub
--------------------------

Sub DoItemEdit(objS ource as Object, objArgs as
DataGridCommand EventArgs)

DataGrid1.EditI temIndex=objArg s.Item.ItemInde x
BindData()

end sub
----------------------------
and here is the BindData ()
Sub BindData()

Dim connectionStrin g As String =
"Provider=Micro soft.Jet.OLEDB. 4.0; Ole DB Services=-4; Data
Source=C:\Issue Tracker"& _
"\Access.md b"
Dim dbConnection As System.Data.IDb Connection = New
System.Data.Ole Db.OleDbConnect ion(connectionS tring)

Dim queryString As String = "SELECT [Users].* FROM
[Users]"
Dim dbCommand As OleDbCommand = New OleDbCommand
dbCommand.Comma ndText = queryString
dbCommand.Conne ction = dbConnection

Dim dataAdapter As OleDbDataAdapte r = New
OleDbDataAdapte r
dataAdapter.Sel ectCommand = dbCommand

dataAdapter.Fil l(dataSet,"User s")
DataGrid1.DataS ource=dataSet
DataGrid1.DataB ind()
end sub

----------------------------------------------

I understand that it's a lengthy question and might take your time. But
being new to asp.net I am really stumped and I have posted my question
after turning pages of a book and relentless GOOGling and I couldn't
find a solution to above.
Any help, suggestions or insights will be highly appreciated. I really
appreciate your time and help.
Thanks in advance.
Thanks,
Erland

Jul 5 '06 #1
1 1233
Hi,

I am still stumped and couldn't really figure out what the problem is,
so I will really appreciate any help or insight.

Thanks,
Erland
Erland wrote:
Hi all,

I have created a simple database table in ACCESS named as "Users" that
contains only two fields "UserID" ( Primary key )and "Password". I am
having problems while UPDATING the records in DataGrid. When i click
Edit button in datagrid and edit my values it actually doesn't update
the vales with newly entered values rather it keep on showing the
previous records. following is the code I used to create datagrid
--------------------------------
<asp:DataGrid id="DataGrid1" runat="server" OnEditCommand=" DoItemEdit"
DataKeyField="U serID" AutoGenerateCol umns="false"
onUpdateCommand ="DoItemUpda te" CellPadding="2" >
<COLUMNS>
<asp:EditComman dColumn HeaderText="Edi t"
EditText="Edit" ButtonType="Lin kButton" CancelText="Can cel"
UpdateText="Upd ate"></asp:EditCommand Column>
<asp:BoundColum n HeaderText="Use r Name"
DataField="User ID" ></asp:BoundColumn >
<asp:BoundColum n HeaderText="Pas sword"
DataField="Pass word" ></asp:BoundColumn >
</COLUMNS>
</asp:DataGrid>
------------------------------------

and following are my Edit and update methods in Vb.net

Sub DoItemUpdate(ob jSource as Object, objArgs as
DataGridCommand EventArgs)
Dim username as TextBox
Dim password as TextBox

Dim u,pass,userid as string

username=objArg s.Item.Cells(1) .Controls(0)
u = username.Text

password=objArg s.Item.Cells(2) .Controls(0)
pass=password.T ext
Label2.Text=u

userid= DataGrid1.DataK eys(objArgs.Ite m.ItemIndex)
Label1.text =pass

'"UPDATE [Users] SET [UserID]=@UserID, [Password]=@Password WHERE
([Users].[UserID]"& _
'" = @UserID)"
Dim sql as String="UPDATE [Users] SET [UserID]='" & u & "',
[Password]='" & pass & _
"' WHERE [Users].[UserID]='"& userid &"'"
Dim connectionStrin g As String = "Provider=Micro soft.Jet.OLEDB. 4.0;
Ole DB Services=-4; Data Source=C:\Issue Tracker"& _
"\Access.md b"
Dim dbConnection As OleDbConnection = New
OleDbConnection (connectionStri ng)
Dim dbCommand As OleDbCommand = New OleDbCommand
dbCommand.Comma ndText = sql
dbCommand.Conne ction = dbConnection
dbConnection.Op en()

dbCommand.Execu teNonQuery()


dbConnection.Cl ose()

DataGrid1.EditI temIndex = -1
BindData()

end sub
--------------------------

Sub DoItemEdit(objS ource as Object, objArgs as
DataGridCommand EventArgs)

DataGrid1.EditI temIndex=objArg s.Item.ItemInde x
BindData()

end sub
----------------------------
and here is the BindData ()
Sub BindData()

Dim connectionStrin g As String =
"Provider=Micro soft.Jet.OLEDB. 4.0; Ole DB Services=-4; Data
Source=C:\Issue Tracker"& _
"\Access.md b"
Dim dbConnection As System.Data.IDb Connection = New
System.Data.Ole Db.OleDbConnect ion(connectionS tring)

Dim queryString As String = "SELECT [Users].* FROM
[Users]"
Dim dbCommand As OleDbCommand = New OleDbCommand
dbCommand.Comma ndText = queryString
dbCommand.Conne ction = dbConnection

Dim dataAdapter As OleDbDataAdapte r = New
OleDbDataAdapte r
dataAdapter.Sel ectCommand = dbCommand

dataAdapter.Fil l(dataSet,"User s")
DataGrid1.DataS ource=dataSet
DataGrid1.DataB ind()
end sub

----------------------------------------------

I understand that it's a lengthy question and might take your time. But
being new to asp.net I am really stumped and I have posted my question
after turning pages of a book and relentless GOOGling and I couldn't
find a solution to above.
Any help, suggestions or insights will be highly appreciated. I really
appreciate your time and help.
Thanks in advance.
Thanks,
Erland
Jul 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1640
by: clyyy2002 | last post by:
At added two column and more column hereafter,I immediately click del button,the program is no problem. but if i first click the DataGrid columnHeader and then click the del button, i find when column is finally ,a error is happen underside is my program.
14
2117
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these grid and write to the database and I set the new Primary Keys and related Fields to the new asigned atuonumbers in the Access.
4
2124
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a Delete button on the end of each row. I am unable to gain access to the event when the button is clicked. I don't fully understand how the click gets connected to the C# code,
1
3036
by: utab | last post by:
Hi there I am trying to read from a file, I am trying to read certain fields,there are 6 fields in this file like --------/--------/--------/--------/--------/--------/ All fields are 8 characters width and I am comparing the first character of the line with the $ sign which seperates different blocks of information $ Nodes of the Entire Model
3
2354
by: aldonnelley | last post by:
Hi all. Just having a weird problem with tkinter. I'm trying to make a gui that shows results from an image search, with a "forward" and "back" button so the user can compare results from different pages. All that's working fine... The problem I'm having is that the images don't show onscreen the first time the "first page" of results shows up. When I click the "search again" button, and have more than the original results page to...
12
5821
by: NOO Recursion | last post by:
Hi everyone! I am trying to write a program that will search a 12x12 for a thing called a "blob". A blob in the grid is made up of asterisks. A blob contains at least one asterisk. If an asterisk is in a blob, an asterisk that is contiguous to it is in the same blob. If a blob has more than two asterisks, then each asterisk in the blob is contiguous to at least one other asterisk in the blob. For example this 12x12 grid has 6 blobs. ...
6
1813
by: Murray Hopkins | last post by:
Hi. THE QUESTION: How do I get a reference to my Object when processing an event handler bound to an html element ? CONTEXT: Sorry if it is a bit long. I am developing a JS calendar tool. One of the requirements is that the calendar will need to display a varying number of months (1..3)
4
2003
by: mkborregaard | last post by:
Hi, I have the weirdest problem, and I can not see what is going wrong. I have made a 2d container class, and am implementing an iterator for that class. However, the ++ operator is behaving very strange. The implementation looks like this (there is a lot of code, but I have only included it all for consistency. The problem is quite small and local): template<typename T> class Row<T> : public std::vector<T> {}; template<typename...
1
1692
by: Francesco Bochicchio | last post by:
Il Mon, 18 Aug 2008 12:15:10 +0100, dudeja.rajat ha scritto: Uhm, I don't think you should use the grid manager to obtain a window like that. The grid manager is for equally distributing widgets both horizontally and vertically. And I'm not sure that you can realize that window look with Tkinter. You could get close by horizontally packing each widget row in a frame and then vertically packing the frames in the window. But the look...
2
6584
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click in the child datagrid and then go to the combobox and choose another vendor. When the new vendor is loaded nothing shows in the datagrid but the itemsource shows the info is there. Know if I click on the child cell and then click back on the...
0
8459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8890
Oralloy
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...
0
8791
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8577
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,...
1
6206
isladogs
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...
0
5677
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();...
0
4376
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2786
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2018
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.