Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
private void bind()
    {
        if (k == "2013")
        {
            RadioButtonList2.Visible = false;
        }
        else
        {
            RadioButtonList1.Visible = false;
        }
        GridView1.Columns[6].Visible = true;
        DataSet dsDetails = new DataSet();
        SqlConnection con = new SqlConnection(strCon);
        SqlDataAdapter daDetails;
        daDetails = new SqlDataAdapter("select row_number() over (order by id) as Sno,id,title,year,platform,domain,abstract from NewIEEE where year=" + k + " order by year desc,sno", con);
        con.Open();

        daDetails.Fill(dsDetails);
        GridView1.DataSource = dsDetails; Cache["ds"] = dsDetails;
        GridView1.DataBind();
        con.Close();
    }



error will be occur in
HTML
daDetails.Fill(dsDetails);


pls help me
Posted
Comments
Maciej Los 9-Oct-14 2:09am    
Does k (year) is a text variable?
Krishna Veni 9-Oct-14 2:28am    
it is a string
Krishna Veni 9-Oct-14 2:29am    
k is string varible
Maciej Los 9-Oct-14 2:36am    
Another question: Does year field is numeric or string data type?
[no name] 9-Oct-14 2:23am    
can you put your debuge and see what's value inside k

There are at least 2 reasons of above error:
1) bad data type
If year field is numeric data type, the query:
SQL
select row_number() over (order by id) as Sno,id,title,year,platform,domain,abstract
from NewIEEE
where year='2013'
order by year desc,sno

must be replaced with:
SQL
select row_number() over (order by id) as Sno,id,title,year,platform,domain,abstract
from NewIEEE
where year=2013
order by year desc,sno


2) k variable is empty (which is inacceptable):
SQL
select row_number() over (order by id) as Sno,id,title,year,platform,domain,abstract
from NewIEEE
where year=''
order by year desc,sno
 
Share this answer
 
Comments
King Fisher 9-Oct-14 3:12am    
its clear my 5+
Maciej Los 9-Oct-14 6:03am    
Thank you ;)
King Fisher 9-Oct-14 6:27am    
:) how are you ? its Me King_Fisher :) Do you Remember Me :)
Maciej Los 9-Oct-14 6:34am    
Thank you, i'm fine. Nice to see you King Fisher vel NELS 140812. And how are you?
King Fisher 9-Oct-14 6:56am    
Thank you, i m good .nice to see you after long time ;)
As Maciej says, the k variable is probably an empty string, so your SQL reads



SQL
... where year = order by ...


Easy to check this by running in debug and looking.

If I really, really need to build SQL strings (not recommended) then I do it to a string variable first, which i then use - that way it is easy to debug, as you can set a breakpoint & look at the value, or write the string out to the output window & take a look.
 
Share this answer
 
Comments
Maciej Los 9-Oct-14 6:05am    
It's good practice to debug program!
+5!
your K value Contain null value.

C#
if(K!="")
{
//your Query

}



so that you can avoid passing Null values
 
Share this answer
 

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



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