Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid

Status
Not open for further replies.

Maximus007

Technical User
Jul 26, 2004
248
US
First I have a question. Can you have a datagrid that allow paging through the records and allow you edit records? I have tried accomplishing that task but not successful. Here's what happens in my application. After paging the record and selecting a record to edit. Once I click on the update button it adds or inserts a that record into the database. Would anyone happen to know why is this happening?

Thank you

R.M

updating code:

Private Sub dgServer_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgServer.UpdateCommand
Dim ServerTable As DstServer.ServersDataTable
ServerTable = DstServer.Servers
Dim ServerRowUpdate As DstServer.ServersRow
ServerRowUpdate = ServerTable.Rows(e.Item.ItemIndex)
ServerRowUpdate.ServerName = CType(e.Item.Cells(1).Controls(0), TextBox).Text
ServerRowUpdate.DateRegistered = Date.Now
SqlDataAdapter1.Update(DstServer)
dgServer.DataSource = DstServer.Servers.DefaultView
dgServer.EditItemIndex = -1
dgServer.DataBind()
End Sub
 
Do you have an Insert subrotine somewhere that may be getting called when you click update?
 
Yes I do! I have an input field that allows the user to add new server. Should perform that task on another page or can I keep everything in one page and change my code arround so it will not affect the updating subrotine?

Here's the Add new server code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim AddServerTbl As DataTable
Dim AddServerRw As DataRow

If Page.IsValid Then
AddServerTbl = DstServer.Tables(0)
AddServerRw = AddServerTbl.NewRow
AddServerRw("ServerName") = txtServerName.Text
AddServerRw("DateRegistered") = Date.Now
AddServerTbl.Rows.Add(AddServerRw)


'Update back-end tabe based on new row

SqlDataAdapter1.Update(DstServer)

'Reset dataset before filling with data fromdb

'Sdataset.Reset()

'Fill dataset with data fro ther server table
txtServerName.Text = ""
SqlDataAdapter1.Fill(DstServer)
dgServer.DataSource = DstServer.Servers.DefaultView
dgServer.DataBind()
End If




End Sub
 
I don't think that is causing the problem. What does the Update statement look like in your SqlDataAdapter?
 
Here the update code:
Private Sub dgServer_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgServer.UpdateCommand

Dim ServerTable As DstServer.ServersDataTable
ServerTable = DstServer.Servers
Dim ServerRowUpdate As DstServer.ServersRow
ServerRowUpdate = ServerTable.Rows(e.Item.ItemIndex)
ServerRowUpdate.ServerName = CType(e.Item.Cells(1).Controls(0), TextBox).Text
ServerRowUpdate.DateRegistered = Date.Now
SqlDataAdapter1.Update(DstServer)
dgServer.EditItemIndex = -1
dgServer.DataSource = DstServer.Servers.DefaultView

dgServer.DataBind()
End Sub
 
You posted that already. What does the Update statement look like that is in the sql data adapter?
 
The SqldataAdapter1

SELECT ServerID, ServerName, DateRegistered FROM Servers
 
That is the select command, what does the Insert and Update commands look like?
 
I don't use adapters but I would guess Maximus007, you are assuming that SqlDataAdapter1.Update(DstServer) would update your records based off your select statement correct?

All your doing is selecting those records. You need to do an Update

e.g.

UPDATE YourTable Set FieldName = Value

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top