ICantSee
asked on
More sql questions
I currently have a page that displays a record from the "requests" table.
If the request is approved I want the "approved column updated accordingly.
This would mean that the statement would have to recognize the current requestID and update its corresponding approved column.
The requests are currently being displayed in a detailsview. I know that I could simply include the approved column in the datasource for the detailsview, but I want other things to happen when the approved button is clicked, so I want to tie it to the approved button instead.
If the request is approved I want the "approved column updated accordingly.
This would mean that the statement would have to recognize the current requestID and update its corresponding approved column.
The requests are currently being displayed in a detailsview. I know that I could simply include the approved column in the datasource for the detailsview, but I want other things to happen when the approved button is clicked, so I want to tie it to the approved button instead.
Is there anything SQL Server related to your question?
ASKER
yes.
The database is a SQL 2008 R2 database. I am trying to find the correct update syntax to update the approved column of a particular record.
My thought is to work off of the requestID of the record being shown in the detailsview, but I don't know how to build that into an update statement.
The database is a SQL 2008 R2 database. I am trying to find the correct update syntax to update the approved column of a particular record.
My thought is to work off of the requestID of the record being shown in the detailsview, but I don't know how to build that into an update statement.
And you're probably developing on a Windows machine but you didn't include your OS as a topic. What I mean is, is there a SQL related answer to your question? Do you need help with a stored procedure or something?
Assuming you only have a single column key, you can pull the DataKey value from your details view, which should contain the primary key for the record being displayed in the DetailsView:
Dim requestID As Integer = CType(DetailsView1.DataKey.Value, Integer)
'// Build query using requestID, etc
ASKER
BriCrowe,
I'm sorry, I am not following your question.
I am using a Windows 7 Pro laptop running Visual Studio 2012. My programming language is VB. The app that I am working on is connecting to a Windows Server 2008 R2 server running SQL Server 2008 R2 SP1.
I have a request table inside my database name "requests"
The request management page has a detailsview that is bound to a dropdownlist. When a staff member has a pending request, his or her name appears in the dropdown list.
A supervisor will select the name from the dropdown list and their request is displayed in a detailsview.
If he decides to approve the request he will click on the approve request button, the approved column will be checked in the corresponding record (the part I am having trouble with) , and email will be sent to the appropriate parties.
There is a "code behind" page that drives this. The statement I am looking for will go in that code behind page.
So I guess my answer is I am looking for an update statement (I think).
Thank you for anytime that you spend on this. All assistance is appreciated.
I'm sorry, I am not following your question.
I am using a Windows 7 Pro laptop running Visual Studio 2012. My programming language is VB. The app that I am working on is connecting to a Windows Server 2008 R2 server running SQL Server 2008 R2 SP1.
I have a request table inside my database name "requests"
The request management page has a detailsview that is bound to a dropdownlist. When a staff member has a pending request, his or her name appears in the dropdown list.
A supervisor will select the name from the dropdown list and their request is displayed in a detailsview.
If he decides to approve the request he will click on the approve request button, the approved column will be checked in the corresponding record (the part I am having trouble with) , and email will be sent to the appropriate parties.
There is a "code behind" page that drives this. The statement I am looking for will go in that code behind page.
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Private _strsql As String
Private Property strsql As String
Get
Return _strsql
End Get
Set(value As String)
_strsql = value
End Set
End Property
Protected Sub ApproveButton_Click(sender As Object, e As EventArgs) Handles ApproveButton.Click
Dim con As New SqlConnection
Dim cmd As New SqlCommand
'Write form data to the database
con = New SqlConnection("Data Source=sqlserver\DATA;Initial Catalog=BT;Integrated Security=True")
con.Open()
strsql =
cmd.CommandText = strsql
cmd.Connection = con
cmd.ExecuteNonQuery()
MsgBox ("Your request has been sent. You will be updated on its status via e-mail.")
con.Close()
con.Dispose()
End Sub
So I guess my answer is I am looking for an update statement (I think).
Thank you for anytime that you spend on this. All assistance is appreciated.
ASKER
Carl Tawn
I think this is what I am looking for, but need a little more info. My programming language is VB if that is helpful.
Dim requestID As Integer = CType(DetailsView1.DataKey .Value, Integer)
'// Build query using requestID, etc
would I complete this just by saying something like:
update approved where requestid=requestid
I think this is what I am looking for, but need a little more info. My programming language is VB if that is helpful.
Dim requestID As Integer = CType(DetailsView1.DataKey
'// Build query using requestID, etc
would I complete this just by saying something like:
update approved where requestid=requestid
Yes, basically. I'm assuming you have set the DataKeyName property of your DetailsView to be "RequestID".
If you have then you would build your SQL string something like:
If you have then you would build your SQL string something like:
'// retrieve the ID of the currently displayed record
Dim requestID As Integer = CType(DetailsView1.DataKey.Value, Integer)
'// Build query to update "Approved" column based on key field
strsql = "UPDATE Requests SET Approved=1 WHERE RequestID = " & requestID
...
ASKER
Carl Tawn,
That works perfectly.
how would we add the comments box text to the database too? its column name is simply comments and its control name is CommentsTextbox ?
I hope I am not pressing my luck. I do appreciate the help.
That works perfectly.
how would we add the comments box text to the database too? its column name is simply comments and its control name is CommentsTextbox ?
I hope I am not pressing my luck. I do appreciate the help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OUTSTANDING. Thank you VERY MUCH.