472,958 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Adding to a Bound DataGrid: What the @#$!% am I doing wrong!

I cannot a row to this bound DataGrid to SAVE MY LIFE! I have tried
everything and I am at a loss. The using goes into add mode with the add
button adds his data then updates with the update button, seems simple.
I am using ALL visual controls (supposedly to simplify things. If I was not
using the visual controls and calling an ExecuteNonQuery no prob.
Please look at my code and tell me what I am doing wrong. Also, what are the
advatages and disadvantages of using the visual controls and typed Datasets.
THANKS SO MUCH!!!!
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If IsPostBack Then
If Not (Request.Form("btnAdd") Is Nothing) Then
Add()
End If
Else
BindGrid()
End If
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
End Sub

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Update()
End Sub

' Bind the database to the table
Private Sub BindGrid()
vdaPasswords.Fill(dsPasswords1)

If Session("dsPasswords") Is Nothing Then
Session("dsPasswords") = dsPasswords1
End If

DataGrid1.DataSource = dsPasswords1
DataGrid1.DataBind()

End Sub

' The "Add" sub
Private Sub Add()

Dim dr As dsPasswords.PasswordsRow

If dsPasswords1 Is Nothing Then
dsPasswords1 = Session("dsPasswords")
End If

dr = dsPasswords1.Tables("Passwords").NewRow()
dr("NUMBER") = 80
dr("USERNAME") = "SDASD"
dsPasswords1.Tables("Passwords").Rows.InsertAt(dr, 0)
DataGrid1.EditItemIndex = 0
BindGrid()

End Sub

' User clicked "update".
Sub Update()
' Either insert a new row or update the existing row here,
' depending on whether adding or not.
DataGrid1.EditItemIndex = -1
BindGrid()
End Sub


Nov 17 '05 #1
2 2655
Hi Aaron,

I have checked your code carefully, and found that the problem should be
vdaPasswords. In BindGrid, dsPasswords1 is filled again, so the new datarow
lost. Please see my comments below:
Private Sub Add()

Dim dr As dsPasswords.PasswordsRow

If dsPasswords1 Is Nothing Then
dsPasswords1 = Session("dsPasswords")
End If

dr = dsPasswords1.Tables("Passwords").NewRow()
dr("NUMBER") = 80
dr("USERNAME") = "SDASD"
dsPasswords1.Tables("Passwords").Rows.InsertAt(dr, 0) //**** Once
you click Add button, a datarow was inserted into the dsPasswords1
DataGrid1.EditItemIndex = 0
BindGrid()//****Then call BindGrid

End Sub

Private Sub BindGrid()
vdaPasswords.Fill(dsPasswords1)//****But here, dsPasswords1 is filled
again, so the new datarow lost.

If Session("dsPasswords") Is Nothing Then
Session("dsPasswords") = dsPasswords1
End If

DataGrid1.DataSource = dsPasswords1
DataGrid1.DataBind()

End Sub

So you should update vdaPasswords after you add a new datarow to
dsPasswords1.

Please check these articles for more information:
Updating the Database with a DataAdapter and the DataSet
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconupdatingdatabasewithdataadapterdataset.asp

Working with a Typed DataSet
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconworkingwithtypeddataset.asp
Hope this helps.

Best Regards,
Lewis Wang

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Aaron Ackerman" <no@spam.com>
| Subject: Adding to a Bound DataGrid: What the @#$!% am I doing wrong!
| Date: Wed, 23 Jul 2003 12:40:21 -0400
| Lines: 76
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <eN**************@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: ric-64-83-27-134-serial-sta.t1.cavtel.net 64.83.27.134
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:161436
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I cannot a row to this bound DataGrid to SAVE MY LIFE! I have tried
| everything and I am at a loss. The using goes into add mode with the add
| button adds his data then updates with the update button, seems simple.
| I am using ALL visual controls (supposedly to simplify things. If I was
not
| using the visual controls and calling an ExecuteNonQuery no prob.
| Please look at my code and tell me what I am doing wrong. Also, what are
the
| advatages and disadvantages of using the visual controls and typed
Datasets.
| THANKS SO MUCH!!!!
|
|
| Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles MyBase.Load
| 'Put user code to initialize the page here
| If IsPostBack Then
| If Not (Request.Form("btnAdd") Is Nothing) Then
| Add()
| End If
| Else
| BindGrid()
| End If
| End Sub
|
|
| Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
| System.EventArgs)
| End Sub
|
| Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles btnUpdate.Click
| Update()
| End Sub
|
|
|
| ' Bind the database to the table
| Private Sub BindGrid()
| vdaPasswords.Fill(dsPasswords1)
|
| If Session("dsPasswords") Is Nothing Then
| Session("dsPasswords") = dsPasswords1
| End If
|
| DataGrid1.DataSource = dsPasswords1
| DataGrid1.DataBind()
|
| End Sub
|
| ' The "Add" sub
| Private Sub Add()
|
| Dim dr As dsPasswords.PasswordsRow
|
| If dsPasswords1 Is Nothing Then
| dsPasswords1 = Session("dsPasswords")
| End If
|
| dr = dsPasswords1.Tables("Passwords").NewRow()
| dr("NUMBER") = 80
| dr("USERNAME") = "SDASD"
| dsPasswords1.Tables("Passwords").Rows.InsertAt(dr, 0)
| DataGrid1.EditItemIndex = 0
| BindGrid()
|
| End Sub
|
| ' User clicked "update".
| Sub Update()
| ' Either insert a new row or update the existing row here,
| ' depending on whether adding or not.
| DataGrid1.EditItemIndex = -1
| BindGrid()
| End Sub
|
|
|
|
|

Nov 17 '05 #2
Hi Aaron,

Thank you for your reply. I wrote a sample code and it works fine on my
machine. You can test it on your machine to see if it helps.

Please let me know if it helps. Thank you.

Lewis,

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: "Aaron Ackerman" <no@spam.com>
| References: <eN**************@TK2MSFTNGP11.phx.gbl>
| Subject: Re: Adding to a Bound DataGrid: What the @#$!% am I doing wrong!
| Date: Mon, 28 Jul 2003 09:50:10 -0400
| Lines: 85
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <O9**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: ric-64-83-27-134-serial-sta.t1.cavtel.net 64.83.27.134
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:162588
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| That doesn't work.
|
| "Aaron Ackerman" <no@spam.com> wrote in message
| news:eN**************@TK2MSFTNGP11.phx.gbl...
| > I cannot a row to this bound DataGrid to SAVE MY LIFE! I have tried
| > everything and I am at a loss. The using goes into add mode with the add
| > button adds his data then updates with the update button, seems simple.
| > I am using ALL visual controls (supposedly to simplify things. If I was
| not
| > using the visual controls and calling an ExecuteNonQuery no prob.
| > Please look at my code and tell me what I am doing wrong. Also, what are
| the
| > advatages and disadvantages of using the visual controls and typed
| Datasets.
| > THANKS SO MUCH!!!!
| >
| >
| > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
| > System.EventArgs) Handles MyBase.Load
| > 'Put user code to initialize the page here
| > If IsPostBack Then
| > If Not (Request.Form("btnAdd") Is Nothing) Then
| > Add()
| > End If
| > Else
| > BindGrid()
| > End If
| > End Sub
| >
| >
| > Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
| > System.EventArgs)
| > End Sub
| >
| > Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
| > System.EventArgs) Handles btnUpdate.Click
| > Update()
| > End Sub
| >
| >
| >
| > ' Bind the database to the table
| > Private Sub BindGrid()
| > vdaPasswords.Fill(dsPasswords1)
| >
| > If Session("dsPasswords") Is Nothing Then
| > Session("dsPasswords") = dsPasswords1
| > End If
| >
| > DataGrid1.DataSource = dsPasswords1
| > DataGrid1.DataBind()
| >
| > End Sub
| >
| > ' The "Add" sub
| > Private Sub Add()
| >
| > Dim dr As dsPasswords.PasswordsRow
| >
| > If dsPasswords1 Is Nothing Then
| > dsPasswords1 = Session("dsPasswords")
| > End If
| >
| > dr = dsPasswords1.Tables("Passwords").NewRow()
| > dr("NUMBER") = 80
| > dr("USERNAME") = "SDASD"
| > dsPasswords1.Tables("Passwords").Rows.InsertAt(dr, 0)
| > DataGrid1.EditItemIndex = 0
| > BindGrid()
| >
| > End Sub
| >
| > ' User clicked "update".
| > Sub Update()
| > ' Either insert a new row or update the existing row here,
| > ' depending on whether adding or not.
| > DataGrid1.EditItemIndex = -1
| > BindGrid()
| > End Sub
| >
| >
| >
| >
|
|
|
Nov 17 '05 #3

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

Similar topics

0
by: Brian Greiwe | last post by:
I posted this in the datagrid forum but got no bites, so I thought I'd post it here as well for some help.... I've created a datagrid with 1 edititemtemplate column. When the user clicks...
0
by: CGuy | last post by:
Hi, I'm working on an ASPX page which has a DataGrid. This DataGrid is bound to a custom object. My requirement is that at rune time, I want the datagrid to display the items that match a...
4
by: Aaron Ackerman | last post by:
I am using typed datasets in an N-Tier Windows app using VB.NET. I know this posting cannot be fully explained in a single post that is why I am asking for someone to point me to a real world...
2
by: Jim | last post by:
In my Win App, I have a datagrid that's bound to a dataset. When the form loads, the datagrid fills. How can I add an empty row to the end of the datagrid during a button click (similar to...
2
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
5
by: Aaron Ackerman | last post by:
I have a bound combobox the appears on a cell within the column of my bound grid when the user clicks on a cell n(In my vb.net WinForm app). I am trying to allow the adding of an item to that bound...
0
by: jy836 | last post by:
Hey all. I've created a DataGrid and bound it to a dataset, but I need to add several columns. The columns that I need to add have to be in the middle of the ones that are already there (as opposed...
0
by: TonyJ | last post by:
Hello! I'm unsure when I can use a bound datagrid and when I can't. What limitations has a bound datagrid? 1. For example if I want to manipulate the data in the datasource before displaying...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.