简体   繁体   中英

error in sql parameter String does not contain definition

I'm getting an 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();

You're looking for sqlDataSoruce.SelectParameters.AddWithValue , SelectCommand is a string .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM