sql参数中的错误字符串不包含定义

时间:2013-12-16 04:15:36

标签: c# asp.net sql sql-server

我收到错误

  

string'不包含'Parameters'的定义,也没有扩展方法'Parameters'可以找到类型'string'的第一个参数(你缺少using指令或汇编引用吗?)

我哪里做错了?

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();

1 个答案:

答案 0 :(得分:4)

您正在寻找sqlDataSoruce.SelectParameters.AddWithValueSelectCommandstring

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource(v=vs.110).aspx