GridView not showing inserted record

  • Thread starter Thread starter David
  • Start date Start date
D

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
 
David said:
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.
 
Back
Top