C
Join ServerC#
help
Help recquired please! I got stuck at using ui controls like dropdowns and radio buttons im .net cor
Ccnetworks8/29/2022
Hi, I got stuck in using ui such as Drop-down list and radio buttons for binding data from db and to push to database as well.
I am confused to pick some best way to do this. Does anyone point some resources or pdfs please?
I am confused to pick some best way to do this. Does anyone point some resources or pdfs please?
BBinto868/29/2022
No resources, but i did something like this so i can maybe help
BBinto868/29/2022
What is your scenario exactly?
Ccnetworks8/30/2022
thank you
I hv drop down list in my mvc create view. Which gets dynamically binder from db
Now it's shows redundant values.
For ex if my table has 3 IT, 2 Admin, a Account items in Dept field, then my drop-down in view, fetches IT 3 times and Adm8n 2 times as it was in database.How to eliminate thus redundancy?
BTW, I just using one table in database.Thank in Advance
I hv drop down list in my mvc create view. Which gets dynamically binder from db
Now it's shows redundant values.
For ex if my table has 3 IT, 2 Admin, a Account items in Dept field, then my drop-down in view, fetches IT 3 times and Adm8n 2 times as it was in database.How to eliminate thus redundancy?
BTW, I just using one table in database.Thank in Advance
BBinto868/30/2022
So u have table something like this?
1. IT
2.IT
3.IT
4.Admin
5.Admin
1. IT
2.IT
3.IT
4.Admin
5.Admin
BBinto868/30/2022
I think you can just use
SELECT DISTINCT
on the db selectCcnetworks8/30/2022
yes.i am scaffolding by database first..Not write a single query.entity framework core does all this.
Is it I need to use a separate Department table in that same db?
like a Dept table with DeptId(pk), DeptName
along with main database table Employee fields( Id(pk), EmpName, DeptId(fk))
I tried this but while establishing fk,pk relation it spit error showing a message that two tables must have same number of fields.
Is it I need to use a separate Department table in that same db?
like a Dept table with DeptId(pk), DeptName
along with main database table Employee fields( Id(pk), EmpName, DeptId(fk))
I tried this but while establishing fk,pk relation it spit error showing a message that two tables must have same number of fields.
BBinto868/30/2022
Um ok im not sure what are you talking about in the second part? But if you are using ef you can just juse linq for the sorting and scree on the sql
Ccnetworks8/30/2022
I try to explain.
sorry just basic thing.i appreciate your spending of time.
Let's for instance, you are doing a sample crud in .net core mvc db first approach.
Name: Employee having three fields
1.Id(key)
2.EmpName
3.Department - drop-down
you have to show a list of department values dynamically retriieved from db and need to binded to this control.
Now, in Index view normally you list the all the data from table in a grid format.
In Create view,as you know you need to show the empty view with drop-down binded with values.
In Edit View, you need to retain the user's details and as you know let them to edit.Here too, I can retain the department choice in drop-down.i did that in my sample.
But when users enter various inputs (records) in create view with same department, I should not repeat any of the dept items binded to the drop down.
Fir that should I need to make a separate table for holding department values? like Employee table and dept table?
Sorry a bit long writeup thanks many!
sorry just basic thing.i appreciate your spending of time.
Let's for instance, you are doing a sample crud in .net core mvc db first approach.
Name: Employee having three fields
1.Id(key)
2.EmpName
3.Department - drop-down
you have to show a list of department values dynamically retriieved from db and need to binded to this control.
Now, in Index view normally you list the all the data from table in a grid format.
In Create view,as you know you need to show the empty view with drop-down binded with values.
In Edit View, you need to retain the user's details and as you know let them to edit.Here too, I can retain the department choice in drop-down.i did that in my sample.
But when users enter various inputs (records) in create view with same department, I should not repeat any of the dept items binded to the drop down.
Fir that should I need to make a separate table for holding department values? like Employee table and dept table?
Sorry a bit long writeup thanks many!
BBinto868/30/2022
Ok i hope i understand you now
BBinto868/30/2022
So if you have a set of options the user needs to chose from, than you want a separet table to store the options and reference the id of given option from main table
Ccnetworks8/31/2022
okay for that I tried to create a Separate Department Table with 2 fields I'd and Name
and I tried to associate it's DepartmentId field to main table Employee as foreign key.
Butt error display that both table must hv equal number of fields for pk and foreign key relationship.
and I tried to associate it's DepartmentId field to main table Employee as foreign key.
Butt error display that both table must hv equal number of fields for pk and foreign key relationship.
Ccnetworks8/31/2022
For example if the main table Employee has 6 fields,then do I need to have 6 fields in Dept table too?
BBinto868/31/2022
That seems weird
Ccnetworks8/31/2022
sorry for respond late.was off a little
BBinto868/31/2022
Where do u get this error from? Ef core?
Ccnetworks8/31/2022
no in sql server mgmt studio 2017
BBinto868/31/2022
Ok i never actualy set up forgein key, i always just specified it in query
Ccnetworks8/31/2022
but I tried creating the Dept table, after the ef scaffolding done and model generated.might be that could render error?
Ccnetworks8/31/2022
oh i see!
BBinto868/31/2022
I think you can do something like put the data in dropdown, than get the id of the selected option and write jt into the DepartmentId
BBinto868/31/2022
I don't think i understand
Ccnetworks8/31/2022
may I know is it a good approach to create table in ql server mgmt studio or need to perform from visual studio?
sorry for basic doubt
sorry for basic doubt
BBinto868/31/2022
I always just do it in the managment studio
Ccnetworks8/31/2022
i meant that first I created Emoloyee table and made d project in visual studio, utilized the efcore and saffolded that single Employee database from sql server.
so far so good.project runs.perfect output.but I 9bserved during runtime my drop-down has values duplicates.like IT dept existed multiple times.
So I later created dept table in managementstudiowith just 2 fields and tried to have the keys on those fields..Then the error displayed in sql server management studio.
so far so good.project runs.perfect output.but I 9bserved during runtime my drop-down has values duplicates.like IT dept existed multiple times.
So I later created dept table in managementstudiowith just 2 fields and tried to have the keys on those fields..Then the error displayed in sql server management studio.
BBinto868/31/2022
Sure i knew all of that
BBinto868/31/2022
Well nvm don't wory sbout this
BBinto868/31/2022
What if you try this?
Ccnetworks8/31/2022
yes sure...
Ccnetworks8/31/2022
I think I don't understand what u are advising entirely? could you please elaborate a little?
BBinto868/31/2022
Ok sure
BBinto868/31/2022
So you take data from your Department table->you feed them to the dropdown->user selects one of the options->you take the option and get the id of the option -> you write that id to the DepartmentId field
Ccnetworks8/31/2022
oh I got it..you mean you need me to create one more field DeptId in the employee table? already I hv EmployeeId as one primary key in employee table
BBinto868/31/2022
Um no
BBinto868/31/2022
Bcs the forgein key doesn't really work, you can just screw on that and just do what i advised
BBinto868/31/2022
You would be writing into your already existing DepartmentId field
Ccnetworks8/31/2022
haha but I only hv Deptment field in Emoloyee table table which is a nvarcharp showing depth....I don't have Dept Id like..with that Dept(name) only I m using in viewbag in action methods inside Controller to move around the Department Name.
Currently only EmployeeId is in my sql. I think u r advising to create separate table for Department with Id and name and suggest me to use them without creating fk right?
Currently only EmployeeId is in my sql. I think u r advising to create separate table for Department with Id and name and suggest me to use them without creating fk right?
BBinto868/31/2022
Yes
BBinto868/31/2022
I thought you have that before, i guess i didint understand you corectly
Ccnetworks8/31/2022
oh in that case how you notify the ef that dept table is also a part of the solution without establishing pk and fk.sorry if it sounds dumb..
Ccnetworks8/31/2022
no I got you...you understood my point before
BBinto868/31/2022
Part of solution you mean like that this table exist in the db?
Ccnetworks8/31/2022
yes yes
BBinto868/31/2022
Um tbh idk, but it should be pretty easy
BBinto868/31/2022
There is going to be some command for that
Ccnetworks8/31/2022
i see)
Ccnetworks8/31/2022
ok ok I will look into.
Ccnetworks8/31/2022
Thank u so much for supporting this far.
Ccnetworks8/31/2022
in db I can make the table inside.but in ef in visual studio, I don't know how to specify it.anyways I will refer,
Ccnetworks8/31/2022
i am glad friend and I really appreciate ur help.thank you so much once again-
BBinto868/31/2022
Ccnetworks8/31/2022
ok sure-
BBinto868/31/2022
No problem
BBinto868/31/2022
Tbh xou are the most polite person i meet on this server so far
Ccnetworks8/31/2022
ohh thank you so much friend for your appreciation.you are so kind.To be honest, for me also, you are the most kind and lovely person who like to support and guide me in here. Your kind words made my day.
Ccnetworks8/31/2022
i will attempt this and check!