Click here to Skip to main content
16,017,373 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
I want to change table rows in my database, instead manual table.

This is my code:
public interface IMainMenuService
{
    List<MainMenuTable> GetAllMenu();
}

public class MainMenuService : IMainMenuService
{
        public List<MainMenuTable> GetAllMenu()
        {
            return new List<MainMenuTable>()
            {
                new MainMenuTable() {Link = "link1", Title = "Title1"},
                new MainMenuTable() {Link = "link2", Title = "Title2"},
                new MainMenuTable() {Link = "link3", Title = "Title3"},
                new MainMenuTable() {Link = "link4", Title = "Title4"}
            };
        }
    }


What I have tried:

I want to change table rows in my database, instead manual table.
Posted
Updated 14-Aug-22 22:19pm
Comments
OriginalGriff 14-Aug-22 16:33pm    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.
Member 10618364 15-Aug-22 0:19am    
the question is crystalClear it isnt matter what did this code. in this code "return new List<mainmenutable>()" i load data manually but i want load data from my table "MainMenuTable" in database.
OriginalGriff 15-Aug-22 0:49am    
"the question is crystalClear"
No, it isn't. It may be to you, but all we get to work with is exactly what you type - we have no other context. And you haven't asked a question at all - just shown us some code which doesn't seem relevant, and told us you want to change rows we can't see, in a table we can't see, in a database we can't see - using "instead manual table" which makes no sense to us at all in isolation.

Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?

That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!

It would also be a good idea if you go here Asking questions is a skill[^] and think about what you need to know, and what you need to tell us in order to get help.

We're not trying to be awkward, we just can't work in a vacuum!
Member 10618364 15-Aug-22 1:54am    
OK this is my table: "MainMenuTable" i want to Return All Of Rows in "MainMenuTable" from this Function= "public List<mainmenutable> GetAllMenu()"
OriginalGriff 15-Aug-22 2:02am    
:sigh:

OK. You have a table - I know the name. What I don't know is where it is, what DB it is stored in, what DB type that is, what the columns might be called, or even what the class "MainMenuTable" or "mainmenutable" might contain.

Or what you have tried, where you are stuck, or what actual help - other than "write me code for me" - you might need.

So, we're peachy really. No more info could possibly be wanted.

I am serious when I say we only get exactly what you type to work with ... Go follow the link I gave you, and read up on how to ask a question. Please?

Based on the limited information available, and the lack of DB code, I understand the question as "How do I work with SQL Server to maintain my data?"

There are fantastic tutorial websites that will answer these questions and more better than we can here in this limited forum.

For Dot Net Core apps, like Asp.Net Core, I recommend the following 2 (depends on your preference):
1. Entity Framework Core Tutorials[^]
2. Entity Framework Core Documentation And Tutorials | Learn Entity Framework Core[^]
 
Share this answer
 
ok I Want Load Main Menu of MySite Dynamically With SqlServer DataBase.
my project is "asp.net core razor page"
I using ComponentView for MainMenu.
I use Service to load mainmenu
this is IMainMenuService Code:
namespace WebApplication4.Utilities.Services.MainMenu
{
    public interface IMainMenuService
    {
        List<MainMenuTable> GetAllMenu();
    }

    public class MainMenuService : IMainMenuService
    {
         public List<MainMenuTable> GetAllMenu()
        {
            return new List<MainMenuTable>()
            {
                new MainMenuTable() {Link = "link1", Title = "عنوان1"},
                new MainMenuTable() {Link = "link2", Title = "عنوان2"},
                new MainMenuTable() {Link = "link3", Title = "عنوان 3"},
                new MainMenuTable() {Link = "link4", Title = "عنوان 4"}
            };
        }
}


this is _Layout file:
C#
@await Component.InvokeAsync("MainMenuComponent")


this is MainMenuComponent:

<pre>namespace WebApplication4.Pages.Shared.Components
{
    public class MainMenuComponent : ViewComponent
    {
        private IMainMenuService _mainMenuService;

        public MainMenuComponent(IMainMenuService mainMenuService)
        {
            _mainMenuService = mainMenuService;
        }

        public async Task<IViewComponentResult> InvokeAsync()
        {
            return View("/Pages/Shared/Components/_MainMenu.cshtml", _mainMenuService.GetAllMenu());
        }
    }
}


Now i Want to Return MainMenuTable Rows in
public List<MainMenuTable> GetAllMenu()
 
Share this answer
 
Comments
Graeme_Grant 15-Aug-22 2:49am    
You posted your question as a solution, not updated the question itself.

You need to press the green "Imrpove Question" link above, then delete this solution.
Member 10618364 15-Aug-22 3:22am    
Why????? i need to new comment and show my code like that but this site dosent have this option
why you dont answer my fu... question what the fu... wrong with you
Graeme_Grant 15-Aug-22 3:40am    
Because that is how questions are asked, as questions, not solutions. When you modify a question, it gets pushed to the front of the questions and is seen as "updated".

Once you do it correctly, then I will look at it.

But, to point you in the right direction, you still have not answered Griff's questions:
1. what database system - MSSQL MySql, PostGresQl, SQLite, etc...
2. how are you acccessing it - EF, Linq2Sql, ADO, etc...
3. what you have tried so far code wise - C#, SQL, ...; etc ...

We still can't see what or how you are doing it. We cannot see your screen from a question in here.
OriginalGriff 15-Aug-22 3:43am    
First off, don't start getting abusive: we do not tolerate that at all here.

Secondly, the reason you don't post "extra info" as a solution is simple: it removes your question from the "unanswered list" and that reduces your chances of getting a genuine answer!
So use the "Improve question" widget, then let me know you've do9ne it and I'll remove this solution and it's comments for you.

OK?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900