2

I have a program in Visual Studio that loads table data from SSMS. Right now, it's hard coded in to load specific tables no matter who logs in.

In SSMS, I have tables of college classes. When a user logs in, I want to run code in Visual Studio to insert the classes they've taken (located in SSMS) into tables in Visual Studio.

The root of my question is: How and in which program do I basically code "user with (current ID) has logged in. Get their data from SSMS and put it in the tables.

You don't have to answer the latter part necessarily but I'm really struggling with getting first part. Getting the persons ID who's logged in.Is it SCOPE_IDENTITY? Is it @@IDENTITY? Trying my best to understand this microsoft doc on scope identity.

Courses: https://i.stack.imgur.com/E34GW.png

Users: https://i.stack.imgur.com/QxFWv.png

Info (loads at top of program): https://i.stack.imgur.com/oMdlA.png

  • The logged in user id is not SCOPE_IDENTITY nor @@IDENTITY. However, it is your application, you should know how to identify the logged in person. Your question is unclear, your users don't run Visual Studio so can you describe your app? – Crowcoder Mar 13 '18 at 18:24
  • It's a degree reporting program. (This is for fun here, don't worry about security, etc). When a user makes an account, they will select what classes they've taken. A table will be made in SSMS for that user that includes all the classes they've taken. I want to load the data in SSMS into a DataGridView (table) in Visual Studio. – tryingtotryhard Mar 13 '18 at 18:31

1 Answers1

0

This has nothing to do with identity. Identity describes auto-incrementing columns on a table.

The easiest way to accomplish this would be with a parameterized stored procedure. When your user logs in, you execute a procedure that will return all the class info for that user ID. If they are each going to be a user/login in SQL Server, you can use

SELECT DATATBASE_PRINICAL_ID() 

to get their id, but chances are that will not align with what is in your table data.

dfundako
  • 8,022
  • 3
  • 18
  • 34
  • Thanks for the reply, I'll look into that! Quick question. If I want to get users data from a table in SSMS, should I try to grab the users ID in SSMS or an arbitrary value such as a username? – tryingtotryhard Mar 13 '18 at 18:32
  • @ColtonHorvath That depends. Add a sample of what your data looks like in your post. – dfundako Mar 13 '18 at 18:35
  • I've added the images. Basically, a new table will be created based on the classes a user selects and says they've completed. When they log in, **their** classes table will load into different parts of the program. I'll do the same with the Info table as well. Which is why I was asking if I should just have the users make usernames instead of me trying to get their logged in ID from SSMS. – tryingtotryhard Mar 13 '18 at 18:43