sql参数中的错误字符串不包含定义。 [英] error in sql parameter String does not contain definition.

查看:110
本文介绍了sql参数中的错误字符串不包含定义。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有错误字符串'不包含'参数'的定义,也没有扩展方法'参数'接受类型'字符串'的第一个参数可以找到(你是否错过了使用指令或程序集)参考?)。我哪里做错了?





hye i'm having error "string' does not contain a definition for 'Parameters' and no extension method 'Parameters' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)". Where did i do wrong?


string connectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\shafiq\\Desktop\\history\\App_Data\\Radiation.mdf;Integrated Security=True;User Instance=True";

            // Create SQLDataSource.
            SqlDataSource sqlDataSource = new SqlDataSource();
            sqlDataSource.ID = "SqlDataSource123";
            this.Page.Controls.Add(sqlDataSource);

            // Bind ConnectionString to SQLDataSource.
            sqlDataSource.ConnectionString = connectionString;
            // Retrieve records with only 5 Columns from Employees table of NorthWind Database.

                sqlDataSource.SelectCommand = "SELECT top 30 [date], [data] FROM [loc1] WHERE (([data] >= '2') AND ([date] >= @startdate) AND ([date] < @enddate)) ORDER BY [data] DESC, [date] DESC";
                sqlDataSource.SelectCommand.Parameters.AddwithValue("@startdate", startdate);
                sqlDataSource.SelectCommand.Parameters.AddwithValue("@enddate", enddate);
                gridmaxdata.DataSource = sqlDataSource;
                gridmaxdata.DataBind();

推荐答案

我没有将值传递给参数,所以@startdate,@ enddate是空参数。

首先你可以从datetimepicker或....传递参数值。
i thing u did not pass value to parameter, so @startdate, @enddate are empty parameter.
first you can pass parameter value from datetimepicker or ....


Hi Siber,



尝试替换以下两行

Hi Siber,

Try to replace the below two lines
sqlDataSource.SelectParameters.Add("@startdate", Convert.ToDateTime(startdate));
sqlDataSource.SelectParameters.Add("@enddate", Convert.ToDateTime(enddate));



在这里你可以看到我已经转换为dateTime类型,因为我相信数据库中的字段是DateTime类型。



注意:在此之前你需要确保startdate和enddate有值。



希望这个帮助你一点。



问候,

RK


Here you can see I have converted to dateTime type since I believe field in database is in DateTime type.

Note: Before that you need to make sure startdate and enddate has values.

Hope this helps you a bit.

Regards,
RK


这篇关于sql参数中的错误字符串不包含定义。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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