Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update with Username

Status
Not open for further replies.

briangriffin

Programmer
Nov 6, 2008
878
US
Database guy here, not the programmer - he's sharp but not too experienced with asp.net.

He's created a page with a datagrid, the users are able to update records based on security in an entitlement table.

The select works fine, and the update works fine except we want to update a database field with the username of the person making the update. Sounds easy since we're successfully passing that value into the select statement to return the appropriate rows to be updated.

Anyway, here's the code so if you have any ideas I'd be most appreciative.

Code:
SelectCommand="select 
d.recordnumber,
a.acctunit as 'Accounting Unit',
b.unitdescription as 'Unit Description',
c.datadescription as 'DataDescription',
case when d.datavalue is null then 0 else d.datavalue end as 'Value'

from 
dbo.Productivity_Security a inner join dbo.Lawson_AccountingUnits b
       on a.acctunit = b.acctunit 
       
left outer join dbo.Productivity_DataDescription c
       on a.acctunit = c.acctunit
              
left outer join dbo.Productivity_DataEntry d
       on c.acctunit = d.acctunit
       and c.datadescriptionid = d.datadescriptionid
       
where 
a.username = @v_user  -- here's where the username is passing properly
and d.datadate = @v_date

order by a.acctunit, c.datadescriptionid" 

UpdateCommand="update productivity_dataentry
set [datavalue] = @Value,
[username] = 'testdomain\testuser', -- passing in hardcoded value for testing
[updatetime] = getdate()

where [recordnumber] = @original_recordnumber" >

Also, the error refers to inability to insert a null value into the table, which is correct - that field is not nullable. But that implies that no value is being assigned to the variable in the update statement.

 

Well, after three days he got it working. I think he was using the wrong variable name - thanks to anyone who was taking a look.
 

False alarm, it's updating but not the correct value. I'm not understanding why @v_user works fine in the select but the same variable does not work in the update - is it going out of scope?
 
the sql's not the problem. where are you assigning the username value to the command? you can get the current user's name from the http context
Code:
User.Identity.Name;
Code:
User.Identity.Name;
Code:
Page.User.Identity.Name;

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top