如何使用存储过程传递id(how to pass id for where using stored procedure)

   IT问题网   2021-02-18 00:00:00

问 题

如何在c#中使用mysql存储过程时传递id for where条件。



存储过程:



  drop   procedure  如果 存在 update_mt_data; 


分隔符#
创建 过程 update_mt_data
帐户名 varchar 200 ),transfilename varchar 200 ))

开始
更新 mt
set

文件名=文件名,
医师=医师,
姓氏=姓氏,
名字=名字,
middlename = middlename,
patientid = patientid,
mrno = mrno,
dateofadmission = dateofadmission,
dateofservice = dateofservice,
rphysician = rphysician,
dateofbirth = dateofbirth,
dictateddatesdifferent = dictateddatesdifferent,
备注=备注,
dateofdictation = dateofdictation,
ccphy = ccphy,
ccphyinvalid = ccphyinvalid,
worktype = worktype

其中 accountname = accountname transfilename = transfilename
;

end

delimiter;


等级:



  public   int  updatemtdata( string  accountname, string  transfilename, string 文件名,datetime dateofdictation, string 姓氏, string 名字,字符串中间名,字符串 dateofservice, string  dateofadmission, string  mrno, string 医师, string 备注,字符串 patientid,字符串 rphysician,字符串 dateofbirth,字符串 worktype, string  ccphy, string  ccphyinvalid, string  dictateddatesdifferent)
{
mysqlconnection con = new mysqlconnection(" server = 192.168.0.10 ; database = anju2; uid =幔; password = harjeet;");
addeditor aedit = new addeditor();

尝试
{

con.open();

mysqlcommand command = new mysqlcommand(" update_mt_data",con);
command.commandtype = commandtype.storedprocedure;
command.parameters.add( new mysqlparameter(" ?accountname",mysql.data.mysqlclient.mysqldbtype.varchar, 200 ));
command.parameters.add( new mysqlparameter(" ?transfilename",mysql.data.mysqlclient.mysqldbtype.varchar, 200 ));
command.parameters.add( new mysqlparameter(" ?filename",mysql.data.mysqlclient.mysqldbtype.varchar, 200 ));

command.parameters.add( new mysqlparameter(" ?dateofdictation",mysql.data.mysqlclient.mysqldbtype.date));

command.parameters.add( new mysqlparameter(" ?姓氏",mysql.data.mysqlclient.mysqldbtype.varchar, 200 ));
command.parameters.add( new mysqlparameter(" ?名字",mysql.data.mysqlclient.mysqldbtype.varchar, 200 ));
command.parameters.add( new mysqlparameter(" ?middlename",mysql.data.mysqlclient.mysqldbtype.varchar, 250 ));
command.parameters.add( new mysqlparameter(" ?dateofservice",mysql.data.mysqlclient.mysqldbtype.varchar, 200 ));
command.parameters.add( new mysqlparameter(" ?dateofadmission",mysql.data.mysqlclient.mysqldbtype.varchar, 200 ));


command.parameters.add( new mysqlparameter(" ?mrno",mysql.data.mysqlclient.mysqldbtype.varchar, 200 ));

command.parameters.add( new mysqlparameter(" ?physician",mysql.data.mysqlclient.mysqldbtype.varchar, 250 ));
command.parameters.add( new mysqlparameter(" ?备注",mysql.data.mysqlclient.mysqldbtype.varchar, 250 ));
command.parameters.add( new mysqlparameter(" ?patientid",mysql.data.mysqlclient.mysqldbtype.varchar, 250 ));

command.parameters.add( new mysqlparameter(" ?rphysician",mysql.data.mysqlclient.mysqldbtype.varchar, 250 ));
command.parameters.add( new mysqlparameter(" ?dateofbirth",mysql.data.mysqlclient.mysqldbtype.varchar, 255 ));
command.parameters.add( new mysqlparameter(" ?worktype",mysql.data.mysqlclient.mysqldbtype.varchar, 250 ));

command.parameters.add( new mysqlparameter(" ?ccphy",mysql.data.mysqlclient.mysqldbtype.varchar, 1000 ));
command.parameters.add( new mysqlparameter(" ?ccphyinvalid",mysql.data.mysqlclient.mysqldbtype.varchar, 1000 ));

command.parameters.add( new mysqlparameter(" ?dictateddatesdifferent",mysql.data.mysqlclient.mysqldbtype.varchar, 200 ));





command.parameters [ 0 ]。value = accountname;
command.parameters [ 1 ]。value = transfilename;
command.parameters [ 2 ]。value = filename;
command.parameters [ 3 ]。value = dateofdictation;
command.parameters [ 4 ]。value =姓氏;
command.parameters [ 5 ]。value = firstname;
command.parameters [ 6 ]。value = middlename;
command.parameters [ 7 ]。value = dateofservice;
command.parameters [ 8 ]。value = dateofadmission;
command.parameters [ 9 ]。value = mrno;
command.parameters [ 10 ]。值=医师;
command.parameters [ 11 ]。value =备注;
command.parameters [ 12 ]。value = patientid;
command.parameters [ 13 ]。value = rphysician;
command.parameters [ 14 ]。value = dateofbirth;
command.parameters [ 15 ]。value = worktype;
command.parameters [ 16 ]。value = ccphy;
command.parameters [ 17 ]。value = ccphyinvalid;
command.parameters [ 18 ]。value = dictateddatesdifferent;



// command.executenonquery();

int updatestr =( int32 )command.executescalar( );

con.close();
return updatestr;


}
catch (例外情况)
{
string str = ex.tostring();
return 0 ;

}
最后
{
con.close();
}
}


代码落后:

 ae.updatemtdata(d。 account_name,dgvdistribution [ 11 ,dgvdistribution.currentrow.index] .value.tostring(),dgvdistribution [ 1  ,dgvdistribution.currentrow.index] .value.tostring(),convert.todatetime(d.dateofdictation),d.lastname,d.firstname,d.middlename,d.dateofservice,d.dateofadmission,d.mrno,d.dictatorname ,d.remarks,d.patientid,d.rphysician,d.dateofbirth,d.worktype,d.ccphy,d.ccphyinvalid,d.dictateddatesdifferent); 




编辑:代码格式化

解决方案

 sqlcommand cmd =  new  sqlcommand(); 
// ...其他代码
cmd.parameters.addwithvalue(" @ id",myidvalue);
cmd.executequery();

只需将 voiceid 添加到:

- 存储过程参数

-mysqlcommand参数

-updatemtdata方法参数

- 并在后面的代码中调用



所以它就像所有其他参数一样,你只是在where子句而不是set子句中使用它。

标签:如何使用存储过程进程传递



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

使用cookie值加载gridview(Load gridview using a cookie value)

problem i have a method to load a gridview according to a ...

只有添加足够的行才能启用垂直滚动条,才会显示ClistBox(ClistBox doesn't display until enough lines are added to enable the vertical scroll bar)

problem i have an application that adds lines to a list b ...

DateTime数据类型的算术运算。(Arithmetic Operations on DateTime Datatype.)

problem hi, i have been trying to find a way to do arit ...

将图像插入Word(Insert Image to Word)

problem how to compress inserted image in word using dsof ...

我如何缩进给定的XML(how can i indent a given XML)

problem is there any easiest way to indent given xml i ...

我想将Outlook消息保存到sql server db(i want to save outlook messages to sql server db)

problem hi could you please help me on saving outlook m ...

我如何在cookie中保存令牌(how I can save the token in the cookie)

problem hi, i am creating the web service au ...

C#.net中的ModalPopupExtender(ModalPopupExtender in C#.net)

problem while i am clicking the modal popup extender wind ...

需要帮助来更改密码表格(need help to change password form)

problem hi everyone, i am still newbie in vb. ...

CMap或CMapPtrToPtr(CMap or CMapPtrToPtr)

problem hi, i want store the objects in cmap ...

如何创建新的任务栏(how to create new task bar)

problem hi, i want to create new taskbar,can any one hel ...

在C#.net中旋转PDF文件(Rotate PDF File in C#.net)

problem hi , how to rotate pdf file in c#.net ...

在C#.Net中旋转图像文件(Rotate Image Files in C#.Net)

problem hi, how to rotate image files(jpeg,ti ...

如何交换字符串中的字符(how to swap characters in a string)

problem hi all. i''m new in .net and i want t ...

如何在SHAREPOINT 2010中集成twitter(How to integrate twitter in SHAREPOINT 2010)

problem hi to all, this is siddiqali working ...

检查应用程序是否正在运行(Check If Application Is Running)

problem is there a way to run a loop that wou ...

如何使用radiobuttonlist?(how to use radiobuttonlist)

problem i want to write select query for selectedindexcha ...

如何计算日期差异和数字差异(How to Calculate Date Diff And Num Diff)

problem glnotranscationdate deposit withdraw transid loan ...

ie6浏览器问题在我的网页上(ie6 browser issue in my web page)

problem my webpage displaying 1 inleft bottom corner only ...

无法在表单上使用控件。(Unable to use controls on the form.)

problem hi, i have created some static insta ...