Home All Groups Group Topic Archive Search About

GridView not showing inserted record

Author
26 Jun 2006 3:24 PM
David
I am using subroutine to add a record to a table that is bound to a GridView
via DataSourceID (SQL table).  I have a link button to do this as I
sometimes need to do special processing.  After the record is inserted, the
new record does not immediately show on the GridView and I'm not sure why.
Below is my code if anyone can help.  Thanks.

Protected Sub BtnNewSubfile_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles BtnNewSubfile.Click

'Inserts a new blank Subfiles record for current file number

Dim conFileData As OleDbConnection

Dim strSQL As String


conFileData = New
OleDbConnection(ConfigurationManager.ConnectionStrings("FiledataOledb").ConnectionString)

conFileData.Open()


strSQL = "INSERT INTO dbo.Subfiles ([SeqNo], [FileNumber])" & _

" SELECT TOP 1 MAX([SeqNo])+1, [FileNumber] FROM dbo.Subfiles WHERE
[FileNumber]=" & txtFileNumber.Text & " GROUP BY [FileNumber]"

Dim cmdInsert As OleDbCommand

cmdInsert = New OleDbCommand(strSQL, conFileData)

cmdInsert.ExecuteNonQuery()

SqlDataSource2.DataBind()

conFileData.Close()

End Sub

Author
27 Jun 2006 3:52 PM
cw
David wrote:
Show quote
> I am using subroutine to add a record to a table that is bound to a GridView
> via DataSourceID (SQL table).  I have a link button to do this as I
> sometimes need to do special processing.  After the record is inserted, the
> new record does not immediately show on the GridView and I'm not sure why.
> Below is my code if anyone can help.  Thanks.
>
> Protected Sub BtnNewSubfile_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles BtnNewSubfile.Click
>
> 'Inserts a new blank Subfiles record for current file number
>
> Dim conFileData As OleDbConnection
>
> Dim strSQL As String
>
>
> conFileData = New
> OleDbConnection(ConfigurationManager.ConnectionStrings("FiledataOledb").ConnectionString)
>
> conFileData.Open()
>
>
> strSQL = "INSERT INTO dbo.Subfiles ([SeqNo], [FileNumber])" & _
>
> " SELECT TOP 1 MAX([SeqNo])+1, [FileNumber] FROM dbo.Subfiles WHERE
> [FileNumber]=" & txtFileNumber.Text & " GROUP BY [FileNumber]"
>
> Dim cmdInsert As OleDbCommand
>
> cmdInsert = New OleDbCommand(strSQL, conFileData)
>
> cmdInsert.ExecuteNonQuery()
>
> SqlDataSource2.DataBind()
>
> conFileData.Close()
>
> End Sub

I'm not sure...but from your code it looks like you are performing the
insert into the server side.
I'm guessing that the grid is actually bound to a local dataset.  With
grids, something called a "Data View Manager" is created that does the
actual binding.  You may wish to look this up in the help file.

IF you are attempting to insert into a local datatable, then I would
expect code like the following (giving in C# psuedo code)

System.Data.Datarow DR=<datatable>.NewRow();
DR[<column>]=<source value>
....
<datatable>.Rows.Add(DR)

Things to try would also be a grid.Refresh() call as well.

Hope this helps.
Author
2 Jul 2006 12:57 AM
ReyN
hello David

you'd have to do a GridView.DataBind ( ) right after the insert

AddThis Social Bookmark Button