|
| Re: Need help with update statement. |
 |
Mon, 17 Mar 2008 19:44:45 +000 |
The one thing you don't want to update is the PlayerID. That's the primary key
which identifies one player record from another. Typically, when you update or
delete, you will tell Access which record to update WHERE PlayerID = ?
The reason that the PlayerType is shown in the GridView is because you selected
that field, and not the PlayerTypeID. The usual thing to do is to add a
DropDownList to the GridView where you want the PlayerType to display, and bind
that to a list of PlayerTypes. This is done by adding a SqlDataSource that
simply gets all PlayerTypes from the database (SELECT PlayerTypeID, PlayerType
FROM PlayerType). The SelectedValue for that DropDownList will be the
PlayerTypeID (SelectedValue='<%# Bind("PlayerTypeID") %>')
|
| Post Reply
|
| Re: Need help with update statement. |
 |
Mon, 17 Mar 2008 19:59:10 +000 |
Thanks. The real problem I am having is having two tables. I can get it to
update fine if I don't include anything from the second table. As soon as I try
to add a record from the second table it does not work. It has something to do
with the where statement, but I'm not sure how to fix it.
so this what works (with one table):
SELECT Player.ID, Player.First_Name, Player.Last_Name, Player.Date_of_Birth,
Player.Address, Player.City, Player.State, Player.Zip_Code, Player.PlayerTypeID
FROM (Player INNER JOIN PlayerType ON Player.PlayerTypeID = PlayerType.ID)
UPDATE [Player] SET [First_Name] = ?, [Last_Name] = ?, [Date_of_Birth] = ?,
[Address] = ?, [City] = ?, [State] = ?, [Zip_Code] = ?, [PlayerTypeID] = ? WHERE
[ID] = ?
I just need to display playertype.playertype, it doesn't need to be editable,
when I add it to the select statement the update does not work anymore.
|
| Post Reply
|
| Re: Need help with update statement. |
 |
Mon, 17 Mar 2008 20:13:52 +000 |
You need to show more code. For example, have you ensured that the parameter
values are declared in the same order as they appear in the SQL?
|
| Post Reply
|
| Need help with update statement. |
 |
Mon, 17 Mar 2008 20:18:55 +000 |
I am trying to write an update statement for a simple search page, I can't get
it to work.
Here is my select clause:
SELECT Player.First_Name, Player.Last_Name, Player.Date_of_Birth,
Player.Address, Player.City, Player.State, Player.Zip_Code,
PlayerType.PlayerType FROM (Player INNER JOIN PlayerType ON Player.PlayerTypeID
= PlayerType.ID) WHERE (Player.First_Name = ?) AND (Player.Last_Name = ?)
I am trying to update the first, last, dob, city, state, zip, and player ID
using gridview update. Another thing I am confused about is when the fields
become editable it shows the Player Type instead of the Player Type ID, which
needs to be edited.
Anyway I've gotten this far:
UPDATE PLAYER
SET FIRST_NAME = @FIRST_NAME,
LAST_NAME=@LAST_NAME,
DATE_OF_BIRTH=@DATE_OF_BIRTH,
ADDRESS = @ADDRESS,
CITY = @CITY,
STATE = @STATE,
ZIP_CODE = @ZIP_CODE,
I'm not sure what to do on the playertype or where statement. Help?
|
| Post Reply
|
| Re: Need help with update statement. |
 |
Mon, 17 Mar 2008 20:24:51 +000 |
Sorry I am being confusing.
This is my first select statement, which takes first name, last name, dob,
address, city, state, zip, and playertypeid from the table PLAYER. Then it takes
the playertype from table PLAYERTYPE.
SELECT Player.First_Name, Player.Last_Name, Player.Date_of_Birth,
Player.Address, Player.City, Player.State, Player.Zip_Code,
PlayerType.PlayerType FROM (Player INNER JOIN PlayerType ON Player.PlayerTypeID
= PlayerType.ID) WHERE (Player.First_Name = ?) AND (Player.Last_Name = ?)
All I am doing there is searching by first and last name from two textboxes and
displaying the results in a gridview. What I need to do next is to be able to
edit/update those fields. That is where I run into a problem. If I deselect
information from the Playertype table then it will update fine, such as:
UPDATE [Player] SET [First_Name] = ?, [Last_Name] = ?, [Date_of_Birth] = ?,
[Address] = ?, [City] = ?, [State] = ?, [Zip_Code] = ?, [PlayerTypeID] = ? WHERE
[ID] = ?
but I need to add the data from the second table (playertype.playertype) to be
updated. I don't know how to add that to the update statement. I'm making this
way harder than it is.....
|
| Post Reply
|
|
|