troubleshooting Question

Executing an SQL statement in Javascript to access forename and surname from SQL Server Database

Avatar of sal-ee
sal-eeFlag for United Kingdom of Great Britain and Northern Ireland asked on
DatabasesJavaScriptScripting Languages
6 Comments1 Solution1577 ViewsLast Modified:
Hello,

This is what I have in place:

1) The forename and surname of the Windows logged on user in a string.
2) I have "split" the string in JavaScript to get the forename and surname separately in an array

function init(){
            var uname = "<%=Replace(Request.ServerVariables("LOGON_USER"),"Domain\","")%>";
            var arr = uname.split(" ");
            var fname = (arr[0]);
            var sname = (arr[1]);
}

This works fine.

This is what I need (if any of it is possible!) :

1) I want to execute an SQL statement in above JavaScript function to find the user above (forename and surname) in the SQL Server 2005 database. Something like: SELECT * FROM users WHERE Firstname = fname AND Surname = sname (I know this isn't the proper syntax, I'm just trying to get the logic across).
I also need to know how to connect to the database before executing the statement.

2) I then need to check a particular column in that record, but I have two issues with this:
    a) I need to have an INSERT INTO query when a page loads (aspx page) and currently have:
        <asp:SqlDataSource runat="server" id="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:Phone extensionsViewer %>" ProviderName="<%$ ConnectionStrings:Phone extensionsViewer.ProviderName %>" InsertCommand="INSERT INTO Phone Extensions$ ('column name') VALUES ('True')"></asp:SqlDataSource>
- This doesn't work!! (But I think I can look into this myself)

   b) The other issue I have is in regards to number 1 above. I would like, after selecting the record for the user, to check that the column I insert into as in step a, contains the value "true". So something like:  SELECT column name FROM users WHERE Firstname = fname AND Surname = sname > from this, check that "column name" = 'true'.

I apologise if I have made this sound really complicated... it does need breaking down in explanation more so please ask me to be clearer if needed, but I would appreciate solutions to any part of the above if not all.

Also, I am using aspx pages.

Thank you in advance.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros