G
Guest
Hi,
Can someone please help me with what I presume is probably a relatively
simple problem! I am trying to return two values (PageID and OfficeID) and
then insert them into another table. My problem is that the values for
PageID and OfficeID are contained in seperate Subs and I don't know or
understand how I should get these values into a third sub that carries out
the insert!
Please see the code below! Thanks for any help!
...CODE
Private PageID As Integer
' Provides the pageID of the record just inserted
Public Sub DGPages_Insert(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
If e.CommandName = "Insert" Then
Dim modDate As String
Dim dtNow As DateTime = DateTime.Now
Dim description As String
Dim txtdescription As TextBox
Dim title As String
Dim txtTitle As TextBox
Dim strSQL As String
modDate = dtNow.Date
'Read in the values of the TextBoxes
txtdescription = e.Item.FindControl("add_description")
description = txtdescription.Text
txtTitle = e.Item.FindControl("add_Title")
title = txtTitle.Text
'Create the appropriate SQL statement
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("PageAdd", Myconn)
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
' Adds Information from the insert area within the datagrid into
tblPageContent
' and returns the record ID
Dim objModDate, objDescription, objTitle, objPageID, objOffice
As SqlParameter
objModDate = cmd.Parameters.Add("@modDate", SqlDbType.DateTime)
objDescription = cmd.Parameters.Add("@description",
SqlDbType.NVarChar)
objTitle = cmd.Parameters.Add("@title", SqlDbType.NVarChar)
objPageID = cmd.Parameters.Add("@PageID", SqlDbType.Int)
objModDate.Direction = ParameterDirection.Input
objDescription.Direction = ParameterDirection.Input
objTitle.Direction = ParameterDirection.Input
cmd.Parameters("@PageID").Direction = ParameterDirection.Output
objModDate.Value = modDate
objDescription.Value = description
objTitle.Value = title
Dim myReader As SqlDataReader = cmd.ExecuteReader()
myReader.Read()
myReader.Close()
PageID = cmd.Parameters("@PageID").Value
Myconn.Close()
'Rebind the DataGrid
DGPages.EditItemIndex = -1
BindData()
End If
End Sub
' Gets the OfficeID from tblOffice
Public Function GetOfficeID_for_Insert() As DataSet
Dim cn As New SqlConnection("strConn")
Dim da As New SqlDataAdapter
Dim ds As New DataSet
Dim cmd As New SqlCommand("SelectOfficeID", cn)
cmd.CommandType = CommandType.StoredProcedure
Dim param As New SqlParameter("@offName", 5)
param.Direction = ParameterDirection.Input
cmd.Parameters.Add(param)
da.SelectCommand = cmd
da.Fill(ds)
Return ds
End Function
' Under Construction
' Should insert the pageID and OfficeID into tblOfficePage
Sub InsertPageID_OfficeID(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
If e.CommandName = "Insert" Then
Dim OfficeID As DataSet
Dim PageID As Integer = PageID
OfficeID = GetOfficeID_for_Insert()
'Create the appropriate SQL statement
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("OfficePageAdd", Myconn)
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
' Adds the OfficeID and PageID into tblOfficePageContent
Dim objOfficeID, objPageID As SqlParameter
objOfficeID = cmd.Parameters.Add("@officeID", SqlDbType.NVarChar)
objPageID = cmd.Parameters.Add("@PageID", SqlDbType.NVarChar)
objOfficeID.Direction = ParameterDirection.Input
objPageID.Direction = ParameterDirection.Input
objOfficeID.Value = OfficeID
objPageID.Value = PageID
Dim myReader As SqlDataReader = cmd.ExecuteReader()
myReader.Read()
myReader.Close()
Myconn.Close()
End If
Can someone please help me with what I presume is probably a relatively
simple problem! I am trying to return two values (PageID and OfficeID) and
then insert them into another table. My problem is that the values for
PageID and OfficeID are contained in seperate Subs and I don't know or
understand how I should get these values into a third sub that carries out
the insert!
Please see the code below! Thanks for any help!
...CODE
Private PageID As Integer
' Provides the pageID of the record just inserted
Public Sub DGPages_Insert(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
If e.CommandName = "Insert" Then
Dim modDate As String
Dim dtNow As DateTime = DateTime.Now
Dim description As String
Dim txtdescription As TextBox
Dim title As String
Dim txtTitle As TextBox
Dim strSQL As String
modDate = dtNow.Date
'Read in the values of the TextBoxes
txtdescription = e.Item.FindControl("add_description")
description = txtdescription.Text
txtTitle = e.Item.FindControl("add_Title")
title = txtTitle.Text
'Create the appropriate SQL statement
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("PageAdd", Myconn)
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
' Adds Information from the insert area within the datagrid into
tblPageContent
' and returns the record ID
Dim objModDate, objDescription, objTitle, objPageID, objOffice
As SqlParameter
objModDate = cmd.Parameters.Add("@modDate", SqlDbType.DateTime)
objDescription = cmd.Parameters.Add("@description",
SqlDbType.NVarChar)
objTitle = cmd.Parameters.Add("@title", SqlDbType.NVarChar)
objPageID = cmd.Parameters.Add("@PageID", SqlDbType.Int)
objModDate.Direction = ParameterDirection.Input
objDescription.Direction = ParameterDirection.Input
objTitle.Direction = ParameterDirection.Input
cmd.Parameters("@PageID").Direction = ParameterDirection.Output
objModDate.Value = modDate
objDescription.Value = description
objTitle.Value = title
Dim myReader As SqlDataReader = cmd.ExecuteReader()
myReader.Read()
myReader.Close()
PageID = cmd.Parameters("@PageID").Value
Myconn.Close()
'Rebind the DataGrid
DGPages.EditItemIndex = -1
BindData()
End If
End Sub
' Gets the OfficeID from tblOffice
Public Function GetOfficeID_for_Insert() As DataSet
Dim cn As New SqlConnection("strConn")
Dim da As New SqlDataAdapter
Dim ds As New DataSet
Dim cmd As New SqlCommand("SelectOfficeID", cn)
cmd.CommandType = CommandType.StoredProcedure
Dim param As New SqlParameter("@offName", 5)
param.Direction = ParameterDirection.Input
cmd.Parameters.Add(param)
da.SelectCommand = cmd
da.Fill(ds)
Return ds
End Function
' Under Construction
' Should insert the pageID and OfficeID into tblOfficePage
Sub InsertPageID_OfficeID(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
If e.CommandName = "Insert" Then
Dim OfficeID As DataSet
Dim PageID As Integer = PageID
OfficeID = GetOfficeID_for_Insert()
'Create the appropriate SQL statement
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("OfficePageAdd", Myconn)
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
' Adds the OfficeID and PageID into tblOfficePageContent
Dim objOfficeID, objPageID As SqlParameter
objOfficeID = cmd.Parameters.Add("@officeID", SqlDbType.NVarChar)
objPageID = cmd.Parameters.Add("@PageID", SqlDbType.NVarChar)
objOfficeID.Direction = ParameterDirection.Input
objPageID.Direction = ParameterDirection.Input
objOfficeID.Value = OfficeID
objPageID.Value = PageID
Dim myReader As SqlDataReader = cmd.ExecuteReader()
myReader.Read()
myReader.Close()
Myconn.Close()
End If