我很需要这里的帮助 [英] i seriously need help here

查看:94
本文介绍了我很需要这里的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 Error 5 ''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

推荐答案

您试图在连接上执行ExecuteScalar,而不是命令.您需要将该行更改为:

You are trying to execute the ExecuteScalar on your connection instead of your command. You need to change that line to be:

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.


这篇关于我很需要这里的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆