Problems with Functions and Insert

G

Guest

Can someone please help! I'm trying to write an insert statement for a
complex datagrid! The database consists of the following data structure!

..tblContent
PageID PK
ModDate
Description
Title

..tblOffice
OfficeID PK
OfficeName
Description

..tblOfficeContent
OfficeID
PageID

What I am trying to do is return the PageID of the information inserted into
tblContent and then get the OfficeID of tblOffice according to the selection
made by the user from the dropdown list and then finally take the pageID and
OfficeID and Insert it into tblOfficeContent

I would be really grateful if someone could give me some assistance with
this! I am reasonably new to ASP.NET and am having a few problems...


Thank you




...:: CODE ::..

' Inserts Page Info into tblContent and returns PageID

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 txtmodDate As TextBox
Dim description As String
Dim txtdescription As TextBox
Dim title As String
Dim txtTitle As TextBox
Dim PageID As Integer

Dim strSQL As String
txtmodDate.Text = dtNow.Date
'Read in the values of the TextBoxes

txtmodDate = e.Item.FindControl("add_modDate")
modDate = txtmodDate.Text
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()

' Add Parameters to the SQL query
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",
System.Data.SqlDbType.Int)

objModDate.Direction = ParameterDirection.Input
objDescription.Direction = ParameterDirection.Input
objTitle.Direction = ParameterDirection.Input
cmd.Parameters("@PageID").Direction =
System.Data.ParameterDirection.Output

objModDate.Value = txtmodDate
objDescription.Value = txtdescription
objTitle.Value = txtTitle
PageID = cmd.Parameters("@PageID").Value

Dim myReader As SqlDataReader = cmd.ExecuteReader()
myReader.Read()

myReader.Close()

Myconn.Close()

'Rebind the DataGrid
DGPages.EditItemIndex = -1
BindData()
End If

End Sub


' Function to return officeID according to office Name selected from the
dropdown list

Function GetOfficeID_for_Insert(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)

Dim office As String
Dim txtOffice As TextBox

txtOffice = e.Item.FindControl("DDLaddOffice")
office = txtOffice.Text

'Create the appropriate SQL statement
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("SelectOfficeID", Myconn)
cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

Dim objOfficeID, objOffName As SqlParameter
objOffName = cmd.Parameters.Add("@offName", SqlDbType.NVarChar)
objOffName.Direction = ParameterDirection.Input
objOffName.Value = txtOffice

Dim myReader As SqlDataReader = cmd.ExecuteReader()
myReader.Read()

myReader.Close()

Myconn.Close()
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top