我们可以在单个类中编写两个命令,但是我在下面使用了错误“错误77没有方法过载”Endexecutereader'取0个参数'感谢你 [英] Can We Write Two Commands In Single Class I Used Below Code But I Am Getting Following Error"Error 77 No Overload For Method 'Endexecutereader' Takes 0 Arguments " Thank U
本文介绍了我们可以在单个类中编写两个命令,但是我在下面使用了错误“错误77没有方法过载”Endexecutereader'取0个参数'感谢你的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
str = "select Total_Fee from newstd_termfee where termnum='" + comboBox3.Text.Trim() + "'and admin_no='" + txtadmin.Text + "'";
str1 = "select (dueamount/2) as 'second term' from newstd_termfee";
com = new SqlCommand(str, cn);
com1 = new SqlCommand(str1,cn);
SqlDataReader reader = com.ExecuteReader();
SqlDataReader r1 = com1.EndExecuteReader();
if (r1.Read())
{
txttermfee.Text = r1["second term"].ToString();
}
if (reader.Read())
{
txttotal.Text = reader["Total_Fee"].ToString();
}
cn.Close();
reader.Close();
r1.Close();
推荐答案
这里有几个问题:
1)EndExecuteReader没有不需要参数的版本: MSDN [ ^ ]
2)要使用EndExecuteReader,必须先调用BeginExecuteReader:MSDN [ ^ ]
3)我根本不认为你的意思是EndExecuteReader - 可能,你想要ExecuteReader。
4)你不能当读卡器已在其上打开时,在同一连接上发出第二个命令,因此您需要两个连接才能同时使用两个读卡器。
[edit]
5)正如Richard所说:不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。请改用参数化查询。 (可以;我相信我没有;不要说...:叹气:
[/ edit]
[edit2]
修复我的c ** k-up:这是Richard,而不是Wes ......:O
[/ edit2]
There are a couple of problems here:
1) EndExecuteReader doesn't have a version that doesn't need a parameter: MSDN[^]
2) To use EndExecuteReader, you must first call BeginExecuteReader first: MSDN[^]
3) I don't think you meant EndExecuteReader at all - probably, you wanted ExecuteReader.
4) You can't issue a second command on the same connection while a reader is already open on it, so you would need two connections to work with two readers simultaneously.
[edit]
5) As Richard said: Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. (Can;t believe I didn;t say that... :sigh:
[/edit]
[edit2]
Fix my c**k-up: It was Richard, not Wes...:O
[/edit2]
这篇关于我们可以在单个类中编写两个命令,但是我在下面使用了错误“错误77没有方法过载”Endexecutereader'取0个参数'感谢你的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文