问题描述
int divide = 100;
string strSQLconnection = ("Data Source");
SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
sqlConnection.Open();
SqlCommand sqlCommand = new SqlCommand("SELECT Discount * UnitPrice /" + divide + "FROM Items.Product where ProductName LIKE" + "''" + item3 + "''", sqlConnection);
decimal answer = Convert.ToDecimal(sqlConnection.ExecuteScalar());
ExecuteScalar严重使我头疼,它给我以下错误错误5``System.Data.SqlClient.SqlConnection"不包含"ExecuteScalar"的定义,没有扩展方法"ExecuteScalar"接受可以找到类型为"System.Data.SqlClient.SqlConnection"的第一个参数(是否缺少using指令或程序集引用?
我试图解决这个问题,但即时通讯.帮助
ExecuteScalar is seriously giving me a headache it gives me the following error Error5''System.Data.SqlClient.SqlConnection'' does not contain a definition for ''ExecuteScalar'' and no extension method ''ExecuteScalar'' accepting a first argument of type ''System.Data.SqlClient.SqlConnection'' could be found (are you missing a using directive or an assembly reference?
i tried to solve this but im out. HELP
推荐答案
sqlCommand.ExecuteScalar()
除此之外,我建议您将命名约定更改得更清晰一些.例如,您有strSQLconnection代表连接字符串,而sqlConnection代表SQL Connection对象.令人困惑.它还没有遵循良好的命名约定准则,这会给您带来麻烦.我建议为您的连接字符串建议使用connectionString,为SQL连接建议使用sqlConnection.这样可以更轻松地了解每个任务的作用.
To add to this, I would recommend that you change your naming conventions to be a bit clearer. For example, you have strSQLconnection representing the connection string while sqlConnection represents the SQL Connection object. That is confusing. It also doesn''t follow good guidelines for naming conventions, which will cause you problems down the road. I would suggest something like connectionString for your connection string and sqlConnection for your SQL connection. That makes it a bit easier to understand what the job is for each.
这篇关于我很需要这里的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!