Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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();
Posted
Comments
JoCodes 15-Dec-13 23:36pm    
Exactly which line your are getting the error?
Jejaka Siber 15-Dec-13 23:41pm    
this line "sqlDataSource.SelectCommand.Parameters.AddwithValue"
JoCodes 15-Dec-13 23:55pm    
The error is related to the datatype of the parameter.
Parameters.AddwithValue("@startdate", startdate); Make sure the startdate and enddate variables are converted to appropriate datatype which they have in the field of your DB table.
JoCodes 16-Dec-13 0:08am    
Have you checked the comment I have added?If still the issue persists revert.
Jejaka Siber 16-Dec-13 0:19am    
the startdate and enddate variable is datetime value the same as the db. but the problem still persists. when i double check the selectcommand, the "parameter" option is unavailable.

i thing u did not pass value to parameter, so @startdate, @enddate are empty parameter.
first you can pass parameter value from datetimepicker or ....
 
Share this answer
 
Comments
Jejaka Siber 16-Dec-13 0:36am    
What do you means by i didn't pass the value?? where do i suppose to pass the value??
Mas11 16-Dec-13 0:40am    
Yes. Same view here
Hi Siber,

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

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
 
Share this answer
 
v6
Comments
Jejaka Siber 16-Dec-13 0:39am    
the code does not work as the error is that it does not recognize SqlDataSource.SelectCommand.Parameters where the error is the Parameters itself. under the SelectCommand, the parameters option is unavailable.
♥…ЯҠ…♥ 16-Dec-13 0:54am    
You didnt get Parameters from intellisense?
Jejaka Siber 16-Dec-13 1:27am    
no... Parameters is not available
♥…ЯҠ…♥ 16-Dec-13 1:29am    
I didnt get you, Parameters is not available means you didnt get value in Parameters or you didnt get Parameters after SelectCommand intellisense?
Jejaka Siber 16-Dec-13 2:05am    
i did not get parameters after selectcommand intellisense. even if i write it directly, it will show error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900