why does one insert work and not the other

wayko

Active member
Joined
Nov 4, 2002
Messages
27
the code is long so i made a .vb of it

i have 2 datagrids that updates and inserts infornation on a database

one of them have a insert new row via a button

Public Sub cb_insert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb_insert.Click
Dim oCmd As New SqlClient.SqlCommand()
oCmd.CommandText = "INSERT INTO dbo.Issue(volno,issueno,issueperiod,year) SELECT MAX(volno) + 1,1,New Issue,max(year) + 1 FROM dbo.Issue"
oCmd.Connection = daDGIssue.SelectCommand.Connection
oCmd.Connection.Open()
Try
oCmd.ExecuteNonQuery()
RefreshVolumeList()
Catch err As SqlClient.SqlException
txtmsg.Text = err.Message
Return
End Try
dgIssue.EditItemIndex = dgIssue.Items.Count
FinishPage()
End Sub
it would create a new row on the bottom of the first datagrid and when u click edit it becomes editable. when u click the update button it would do insert since it would do this

If dsDGIssue.Tables(0).Rows(nIdx).RowState = DataRowState.Added Then
oCmd = New SqlClient.SqlCommand()
With oCmd
oCmd.CommandText = "INSERT INTO dbo.Issue(volno,issueno,issueperiod,year, MagazineTitle, notes)" _
& " VALUES(@VolNo,@IssueNo, @IssuePer, @Year, @MagTitle, @Notes) "

.Parameters.Add("@VolNo", dgVolno)
.Parameters.Add("@IssueNo", uIssueNo)
.Parameters.Add("@IssuePer", uIssuePeriod)
.Parameters.Add("@Year", uYear)
.Parameters.Add("@MagTitle", uMagTitle)
.Parameters.Add("@Notes", uNotes)
.Connection = daDGIssue.SelectCommand.Connection
End With
the 2nd datagrid has information inserted when a linkbutton on the first datagrid is pushed
but when i click update it goes to this

Else
oCmd = daCover.UpdateCommand
daCover.UpdateCommand.Parameters("@IssueId").Value = dgIssueid
daCover.UpdateCommand.Parameters("@Caption").Value = uCaption
daCover.UpdateCommand.Parameters("@PhotogCreditID").Value = uname
daCover.UpdateCommand.Parameters("@tn_width").Value = uTnwidth
daCover.UpdateCommand.Parameters("@tn_height").Value = uTnHeight
daCover.UpdateCommand.Parameters("@Large_image").Value = uLargeimage
daCover.UpdateCommand.Parameters("@full_width").Value = uFullwidth
daCover.UpdateCommand.Parameters("@full_height").Value = uFullheight
daCover.UpdateCommand.Parameters("@Notes").Value = uNotes
daCover.UpdateCommand.Parameters("@Image").Value = utnImage
End If

If oCmd.Connection.State = ConnectionState.Closed Then
oCmd.Connection.Open()
End If

Try
oCmd.ExecuteNonQuery()
Catch err As SqlClient.SqlException
txtmsg.Text = err.Message
Return
End Try
oCmd.Connection.Close()

reload data so we refect what was actually saved
LoadDataSet()
dgCover.EditItemIndex = -1
FinishPage()
dgCover.Visible = True
End Sub
and since there is no physical attributes it doesnt update

when i do a quickwatch on DsCover.Tables(0).Rows(nIdx).RowState it states that it was unchanged

dont know why :mad: :confused: :-\
 

Attachments

Last edited by a moderator:
where is nIdx coming from? have you tried HasChanges() on the dataset to see if it is reporting any changes -- maybe you just dont have the right nIdx.

on a side note, it looks like youre going through the trouble of setting up the dataAdapter, why not just call its update method and let it figure this stuff out for you?
 
If dsDGIssue.Tables(0).Rows(nIdx).RowState always says unchanged
i tried If dsDGIssue.Tables(0).Rows(nIdx).RowState <> DataRowState.Added it works the first time but since it always unchanged it would never update i tried doing a work around but thats not the way to go
 
also is there a way to set a cursor to blink on a textbox on load
ie peron goes in webform and the first textbox already has the cursor blinking and waiting no need for mouse click
 
Have you checked HasChanges() on the whole dataset?

You should start a new thread when you have totally unrelated questions. but as far as I know you cant change the clients cursor on a webform.
 
no i havent
i tried DsCover.Tables(0).Rows(nIdx).RowState.Unchanged = DataRowState.Added
still the same problem
the funny thing is when i do it to another datagrid using a button on the form it works fine
but when i do it from a datagrid button i get the error
 
With your "blinking cursor" question, I misunderstood you. The textbox has a .focus() method that you can use the bodys onLoad() event to call. You could look at the source behind most any professional web page and see this in action, Google is an example.

As it turns out, I was also wrong about the answer I gave to what I thought the question was. It turns out you *can* change the cursor using CSS on the client. Im not sure all the options but I just saw where you can change it to the question mark by
a:hover{cursor:help} in the stylesheet. Not that this was your question, I just like to follow up when I give bum scoop:(
 
Back
Top