欢迎光临
我们一直在努力

如何使用数据查询的Parameters中的output属性取的返回值-.NET教程,数据库应用

建站超值云服务器,限时71元/月

public int addmessage(int moduleid, int fatherid, string username, string title, string body, string face) {

            if (username.length < 1) {
                username = "unknown";
            }

            // create instance of connection and command object
            sqlconnection myconnection = new sqlconnection(configurationsettings.appsettings["connectionstring"]);
            sqlcommand mycommand = new sqlcommand("up_posttopic", myconnection);

            // mark the command as a sproc
            mycommand.commandtype = commandtype.storedprocedure;

            // add parameters to sproc
            sqlparameter parameteritemid = new sqlparameter("@itemid", sqldbtype.int, 4);
            parameteritemid.direction = parameterdirection.output;
            mycommand.parameters.add(parameteritemid);

        sqlparameter parameterfatherid = new sqlparameter("@fatherid", sqldbtype.int, 4);
            parameterfatherid.value = fatherid;
            mycommand.parameters.add(parameterfatherid);

        sqlparameter parametermoduleid = new sqlparameter("@moduleid", sqldbtype.int, 4);
            parametermoduleid.value = moduleid;
            mycommand.parameters.add(parametermoduleid);

        sqlparameter parameterusername = new sqlparameter("@createdbyuser", sqldbtype.nvarchar, 100);
            parameterusername.value = username;
            mycommand.parameters.add(parameterusername);

            sqlparameter parametertitle = new sqlparameter("@title", sqldbtype.nvarchar, 100);
            parametertitle.value = title;
            mycommand.parameters.add(parametertitle);

            sqlparameter parameterbody = new sqlparameter("@content", sqldbtype.nvarchar, 4000);
            parameterbody.value = body;
            mycommand.parameters.add(parameterbody);

        sqlparameter parameterface = new sqlparameter("@face", sqldbtype.nvarchar, 100);
            parameterface.value = face;
            mycommand.parameters.add(parameterface);

            myconnection.open();
            mycommand.executenonquery();
            myconnection.close();

            return (int) parameteritemid.value;
        }
 

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 如何使用数据查询的Parameters中的output属性取的返回值-.NET教程,数据库应用
分享到: 更多 (0)

相关推荐

  • 暂无文章