So i have a database for the customers details and i have set up a DetailsView so that the customers can view their details and edit them and update them. It updates but the problem is that it gets the users details via the UserName, I set the UserName property
to not be able to edit it as i want to leave it as default, but when i update it updates everything except the UserName, so all i can do is just leave it to show to UserName property but i dont want that because i dont want the user to edit his username. Heres
the code to it:
DataFile="~/App_Data/ASPNetDB.mdb"
InsertCommand="INSERT INTO [tbl_Customer] ([UserID], [Title], [UserName], [Firstname], [Surname], [Address], [Postcode], [Mobile_Number], [Email], [Rental_Number]) VALUES (@UserID, @Title, @UserName, @Firstname, @Surname, @Address, @Postcode, @Mobile_Number,
@Email, @Rental_Number)"
SelectCommand="SELECT * FROM [tbl_Customer] WHERE ([UserName] = )"
UpdateCommand="UPDATE [tbl_Customer] SET [Title] = @Title, [UserName] = @UserName, [Firstname] = @Firstname, [Surname] = @Surname, [Address] = @Address, [Postcode] = @Postcode, [Mobile_Number] = @Mobile_Number, [Email] = @Email, [Rental_Number] = @Rental_Number
WHERE (([UserID] = @UserID) OR ([UserID] IS NULL AND @UserID IS NULL) OR ([UserName] IS NULL AND @UserName IS NULL))">
I've tried removing the UserName field from updating but it then leaves the field blank and messes it up, can anyone please help me out?
Simply set the BoundField readonly property to true, then remove the field from update command (set fieldname =...)
I've tried that before, but it doesn't work when i edit and click update it doesn't do anything?
When using access database you need to count the "?", the first update parameter is for first "?" and soon until the last parameter for last "?". Match the "?" and parameter by the order. I suggest you using single parameter as WHERE statement. When you remove
one "?", you need to remove the parameter also, if not you will pass wrong parameter value. This behavior not happen in SqlDataSource because you able to give parameter name like @Userid, and don't worry about the order in SqlDataSource.
MY WHERE statements is UserName = session, Look all i want to do is leave the UserName value as default and update everything else except that field, I don;t know what im doing wrong
Afaik, parameter name in update/insert/delete command actually not work in AccessDataSource. Concern to the order. First parameter (whatever name) in update command get value from first update parameter.
Afaik, parameter name in update/insert/delete command actually not work in AccessDataSource. Concern to the order. First parameter (whatever name) in update command get value from first update parameter.
Dont worry I fixed it through the AccessDataSource, cheers anyway
沒有留言:
張貼留言