Monday, March 12, 2012

question about excute store procedure

Hi, all

i create a function("changefilepermission") to execute a procedure ("grant_file_access") to change the file permission. i click the permission checkbox to change new permission, after that i will click the submit button to update change to the database. but it does not change to the database. this is my part of code. is anybody can give me a help?

thanks in advanced!!!!!!!!!


Private Sub btnsubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSubmit.Click

Dim FileTitle As New String("")
Dim FileName As New String("")

FileName = DGPermission.Items.Item(0).Cells(0).Text 'retrieve filename from datagrid
FileTitle = DatabaseCommand(userid, "fa_title", filename) ' retrieve the filetitle from table

Dim permission As Char ' set the permission value
If (CkRead.Checked) Then
Permission = "r"
ElseIf (CkWrite.Checked) Then
Permission = "w"
ElseIf (CkExecute.Checked) Then
Permission = "o"
End If

Try
' call the store procedure function by passing 4 value
ChangeFileAccess(userid, FileName, FileTitle, Permission) '
Catch ex As Exception
lblErrorMsg.Text = ex.ToString
End Try
End Sub

' execute store procedure function
Public Sub ChangeFileAccess(ByVal userid As String, ByVal DiskFilename As String, ByVal Title As String, ByVal Access As Char)
Dim UpdateCommand As SqlCommand
UpdateCommand = New SqlCommand

With UpdateCommand
.Connection = SqlConnection
.CommandType = CommandType.StoredProcedure
.CommandText = "Grant_File_Access"
.Parameters.Add("@.vu_id", SqlDbType.VarChar, 20).Value = userid
.Parameters.Add("@.DiskFilename", SqlDbType.VarChar, 64).Value = DiskFilename
.Parameters.Add("@.Title", SqlDbType.VarChar, 50).Value = Title
.Parameters.Add("@.Access", SqlDbType.Char, 1).Value = Access
End With

Try
UpdateCommand.Connection.Open()
UpdateCommand.ExecuteReader() ' call the store procedure
UpdateCommand.Connection.Close()
Catch ex As Exception
lblErrorMsg.Text = ex.ToString
End Try
End Sub

What does your stored procedure look like?

Terri

No comments:

Post a Comment