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
|
|
|
|
|