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 :-\
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 :-\
Attachments
Last edited by a moderator: