更新我的数据库

发布于 2024-10-10 03:38:07 字数 569 浏览 3 评论 0原文

我是亚音速的新手,在尝试从 SQL Server 更新数据库时遇到问题。我创建了一个 gridview,但仍然没有返回更新结果。你能帮我吗?它在 dc.AddMostaHse() 上收到错误代码; (无法隐式将类型“void”转换为“对象”)

正在完成的代码

这是 DataAccess.cs 页面public void AddMostaHse() {

        Mosta.MostaHSE1 xx = new MostaHSE1();
        xx.ID = 94;
        xx.FunctionLocation = "lza94";
        xx.acno = 12;
        xx.Save();
    }

将其与 gridview 绑定。 {

        DataAccess dc = new DataAccess();
        gvtest.DataSource = dc.AddMostaHse();
        gvtest.DataBind();

    }

I am new with the subsonic, and I have a problem when trying to update the database from the sql server. I have created a gridview by still is not returning the updates results. can you please help me? its getting an error code on dc.AddMostaHse();
(Cannot implicity convert type 'void to 'object')

Here is the code being done of DataAccess.cs page

public void AddMostaHse()
{

        Mosta.MostaHSE1 xx = new MostaHSE1();
        xx.ID = 94;
        xx.FunctionLocation = "lza94";
        xx.acno = 12;
        xx.Save();
    }

Binding it with the gridview.
{

        DataAccess dc = new DataAccess();
        gvtest.DataSource = dc.AddMostaHse();
        gvtest.DataBind();

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

合久必婚 2024-10-17 03:38:07

这没有多大意义。您的 gridview 应该与读取操作绑定。您当前正在根据您提供的内容将其绑定到插入/写入操作。您可能应该获取 MostaHSE1() 的集合并将其显示在网格视图中。 Read 函数的返回类型很可能应该是 DataTable 或 DataSet。

您的 AddMostHse1() 看起来应该可以工作,但是您希望将 gridview 之外的不同事件作为目标来执行此操作。也许 RowEditEnding 或其他一些事件。

This doesn't make much sense. Your gridview should be being bound from a Read operation. You are currently binding it to a Insert/Write operation based on what you have provided. You should probably be grabbing a collection of MostaHSE1() and displaying that in your gridview. The return type of your Read function should most likely be DataTable or DataSet.

Your AddMostHse1() appears it should work, but you want to target a different event off of the gridview to do this. Maybe RowEditEnding or some other event.

墨离汐 2024-10-17 03:38:07

您的方法 AddMostaHse 返回 void (无返回)。您不能将数据网格绑定到 void。如果您想将数据网格绑定到您刚刚在方法中创建的对象,则将您的方法更改为:

public MostaHSE1 AddMostaHse() {

        Mosta.MostaHSE1 xx = new MostaHSE1();
        xx.ID = 94;
        xx.FunctionLocation = "lza94";
        xx.acno = 12;
        xx.Save();
        return xx;
    }

对我来说,为什么要将一个对象绑定到数据网格(更不用说为什么要将这样创建的对象绑定到datagrid,我假设您只是在测试),通常您绑定对象的集合..因此这可能不会带来您想要的结果。

数据网格更常见的候选者是这样的:

public IEnumerable<MostaHSE1> GetAllMostaHse() {

        return Mosta.MostaHSE1.All();

    }

Your method AddMostaHse is returning void (no return). You cannot bind a datagrid to void. If you want to bind the datagrid to the object you just created in the method then change your method to:

public MostaHSE1 AddMostaHse() {

        Mosta.MostaHSE1 xx = new MostaHSE1();
        xx.ID = 94;
        xx.FunctionLocation = "lza94";
        xx.acno = 12;
        xx.Save();
        return xx;
    }

It seems strange to me why you are binding one object to a datagrid (letting alone why would you bind a created object like that to a datagrid, I assume you are just testing), usually you bind a collection of objects..therefore this may not bring the result you want.

A more common candidate for your datagrid would be something like:

public IEnumerable<MostaHSE1> GetAllMostaHse() {

        return Mosta.MostaHSE1.All();

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文