473,729 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.EventArg s) 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(By Val sender As System.Object, ByVal e As
System.EventArg s)
End Sub

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

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

If Session("dsPass words") Is Nothing Then
Session("dsPass words") = dsPasswords1
End If

DataGrid1.DataS ource = dsPasswords1
DataGrid1.DataB ind()

End Sub

' The "Add" sub
Private Sub Add()

Dim dr As dsPasswords.Pas swordsRow

If dsPasswords1 Is Nothing Then
dsPasswords1 = Session("dsPass words")
End If

dr = dsPasswords1.Ta bles("Passwords ").NewRow()
dr("NUMBER") = 80
dr("USERNAME") = "SDASD"
dsPasswords1.Ta bles("Passwords ").Rows.InsertA t(dr, 0)
DataGrid1.EditI temIndex = 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.EditI temIndex = -1
BindGrid()
End Sub


Nov 17 '05 #1
2 2708
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.Pas swordsRow

If dsPasswords1 Is Nothing Then
dsPasswords1 = Session("dsPass words")
End If

dr = dsPasswords1.Ta bles("Passwords ").NewRow()
dr("NUMBER") = 80
dr("USERNAME") = "SDASD"
dsPasswords1.Ta bles("Passwords ").Rows.InsertA t(dr, 0) //**** Once
you click Add button, a datarow was inserted into the dsPasswords1
DataGrid1.EditI temIndex = 0
BindGrid()//****Then call BindGrid

End Sub

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

If Session("dsPass words") Is Nothing Then
Session("dsPass words") = dsPasswords1
End If

DataGrid1.DataS ource = dsPasswords1
DataGrid1.DataB ind()

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/cpconupdatingda tabasewithdataa dapterdataset.a sp

Working with a Typed DataSet
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconworkingwit htypeddataset.a sp
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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: ric-64-83-27-134-serial-sta.t1.cavtel.n et 64.83.27.134
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP11.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:1614 36
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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.EventArg s) 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(By Val sender As System.Object, ByVal e As
| System.EventArg s)
| End Sub
|
| Private Sub btnUpdate_Click (ByVal sender As System.Object, ByVal e As
| System.EventArg s) Handles btnUpdate.Click
| Update()
| End Sub
|
|
|
| ' Bind the database to the table
| Private Sub BindGrid()
| vdaPasswords.Fi ll(dsPasswords1 )
|
| If Session("dsPass words") Is Nothing Then
| Session("dsPass words") = dsPasswords1
| End If
|
| DataGrid1.DataS ource = dsPasswords1
| DataGrid1.DataB ind()
|
| End Sub
|
| ' The "Add" sub
| Private Sub Add()
|
| Dim dr As dsPasswords.Pas swordsRow
|
| If dsPasswords1 Is Nothing Then
| dsPasswords1 = Session("dsPass words")
| End If
|
| dr = dsPasswords1.Ta bles("Passwords ").NewRow()
| dr("NUMBER") = 80
| dr("USERNAME") = "SDASD"
| dsPasswords1.Ta bles("Passwords ").Rows.InsertA t(dr, 0)
| DataGrid1.EditI temIndex = 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.EditI temIndex = -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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: ric-64-83-27-134-serial-sta.t1.cavtel.n et 64.83.27.134
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:1625 88
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| That doesn't work.
|
| "Aaron Ackerman" <no@spam.com> wrote in message
| news:eN******** ******@TK2MSFTN GP11.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.EventArg s) 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(By Val sender As System.Object, ByVal e As
| > System.EventArg s)
| > End Sub
| >
| > Private Sub btnUpdate_Click (ByVal sender As System.Object, ByVal e As
| > System.EventArg s) Handles btnUpdate.Click
| > Update()
| > End Sub
| >
| >
| >
| > ' Bind the database to the table
| > Private Sub BindGrid()
| > vdaPasswords.Fi ll(dsPasswords1 )
| >
| > If Session("dsPass words") Is Nothing Then
| > Session("dsPass words") = dsPasswords1
| > End If
| >
| > DataGrid1.DataS ource = dsPasswords1
| > DataGrid1.DataB ind()
| >
| > End Sub
| >
| > ' The "Add" sub
| > Private Sub Add()
| >
| > Dim dr As dsPasswords.Pas swordsRow
| >
| > If dsPasswords1 Is Nothing Then
| > dsPasswords1 = Session("dsPass words")
| > End If
| >
| > dr = dsPasswords1.Ta bles("Passwords ").NewRow()
| > dr("NUMBER") = 80
| > dr("USERNAME") = "SDASD"
| > dsPasswords1.Ta bles("Passwords ").Rows.InsertA t(dr, 0)
| > DataGrid1.EditI temIndex = 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.EditI temIndex = -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
2685
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 edit, it spans the entire width of the datagrid (removing the other cells). This column has several controls in it (text boxes, radiobuttons, and a dropdownlist). Also, on the itemdatabound, I am adding another row to the datagrid (above the...
0
1249
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 certain criteria. For example, I have a custom collection named Users to which the DataGrid is bound. The Users collection represents the entire list of users for my system. But when displaying the datagrid, I want to display only those users that...
4
3572
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 tutorial (in vb.net) that can show me how to use a bound Datagrid to it's fullest potential. I need to utilize the bound Datagrid in two modes. One were a bound Datagrid can be in edited directly utilizing bound combos and textbox right on the grid,...
2
10004
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 pressing Tab when mouse pointer is on last field of last record of datagrid)? The datagrid's read-only so the user won't be able to modify it unless he wants to add a new record via the datagrid (by adding the empty row). Also, if I modify the...
2
3638
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 a row. Everything works just fine. BUT I would like to add a button to (for example) the DataGrid header, which when pressed will add a new row to the datagrid. This should then allow the user to enter information into text boxes (in some...
3
4879
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 the best method? Do you have a sample of how to do this?
5
4662
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 combo by allowing the user to dynamically type in the new value directly in the combo box whcih in turn updates the lookup table and then when they have finished leaves that particular cell on the grid with the correct value. Seems...
0
943
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 to being appended after the last orginal column). These new columns will not be bound to the dataset. If possible, I'd appreciate it if someone could also give me an explanation of how to add a non-bound row below all original rows, which I will...
0
1236
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 the data in the datagrid can I then use a bound datagrid? 2. For example if I only want to display some of the columns of a datasource table can I then use a bound datagrid? 3. For example if I some of the columns in a datagrid should be readonly...
0
8913
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
8761
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,...
0
9426
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...
1
9200
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,...
0
6016
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
4525
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...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
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
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.