这段代码中的错误是什么?它无法在数据库中保存数据 [英] What's the error in this code? Its not working not able to save data in the database

查看:52
本文介绍了这段代码中的错误是什么?它无法在数据库中保存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        ProductModel productModel = new ProductModel();
        Product product = CreateProduct();

        lblResult.Text = productModel.InsertProduct(product);



    }





我的尝试:





What I have tried:

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        ProductModel productModel = new ProductModel();
        Product product = CreateProduct();

        lblResult.Text = productModel.InsertProduct(product);



    }

推荐答案

我只能看到(或建议)一个这里的事情,

I can only see (or suggest) one thing here,
lblResult.Text = productModel.InsertProduct(product);



InsertProduct 函数必须返回字符串值,因为 Text 属性 Label 对象有一个String类型,所以要么这样做,要么在结果上调用ToString函数,比如,


The InsertProduct function must return a string value, because the Text property of Label objects has a type of String, so either do that, or call a ToString function on the result, like,

lblResult.Text = productModel.InsertProduct(product).ToString();



其次,从你捕获该代码的任何地方,你需要问他们为什么写这个代码办法。此外,您可以将代码更改为以下代码,这将是一种更好的方法,


Secondly, from wherever you captured that code, you need to ask them why they wrote it this way. Also, you can change the code to the following one and would be a better approach,

productModel.InsertProduct(product);
lblResult.Text = "Product added."



很简单,也有更好的用户体验!


Much simple, and a better UX as well!


这篇关于这段代码中的错误是什么?它无法在数据库中保存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆