如何使用数据查询的Parameters中的output属性取的返回值
2024-07-21 02:23:49
供稿:网友
 
本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。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;
        }