Click here to Skip to main content
15,915,324 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to select data from gridview whose reqest.query string is chat giv c# code for this

C#
string up = Request.QueryString[suupliername];
GridView1.DataSource = obj.selectmultiple("select distinct cat from data1 where supplier="+up+"")


i got error in this code is invallide colums name but i chek all colums name are right in data base so what i change in this code???

C#
where selectmultiple is a function which i make in c# class file

    public SqlDataReader selectparticular(string query)
    {
        command.Connection = connection;
        command.CommandText = query;
        connection.Open();
        SqlDataReader dr = command.ExecuteReader();
        return dr;
    }
Posted
Updated 26-Jun-12 22:58pm
v2
Comments
Sandeep Mewara 27-Jun-12 5:01am    
Which part of Solution 1 & Solution 2 was confusing to you? http://www.codeproject.com/Questions/411246/Csharp-code-for-request-query-string

You ignore our replies, did not made the changes asked and do a repost of same question again. Not good.

i got error in this code is invallide colums name but i chek all colums name are right in data base so what i change in this code???
(Answering in your terms now, forget our suggestions[^])
Based on what you say, your query just asks for one column. So, based on error, look for 2 things:
1. You have a column named 'cat' in your table 'data1'
2. Make sure your query formed is correct and fetches data if you paste it in your SQL directly. For now, I see an issue already pointed earlier, based on names 'up' is a string and the way you pass it to SQL is an int datatype. You need to put single quotes around the value passed for supplier . Correct it to:
C#
GridView1.DataSource = obj.selectmultiple("select distinct cat from data1 where supplier='"+up+"'")


Now, don't repost again. Verify 1 & 2, share your result to move ahead.
 
Share this answer
 
v2
Comments
AshishChaudha 27-Jun-12 5:08am    
Good Reply..my 5!
except of doing

C#
string up = Request.QueryString[suupliername];
GridView1.DataSource = obj.selectmultiple("select distinct cat from data1 where supplier="+up+"");


do like following:

C#
string up = Request.QueryString["suupliername"];
GridView1.DataSource = obj.selectmultiple("select distinct cat from data1 where supplier='"+up+"'")




Thanks
Ashish
 
Share this answer
 
v2
Comments
Sandeep Mewara 27-Jun-12 5:07am    
How is this related to 'invalid column name error'?
AshishChaudha 27-Jun-12 5:12am    
let here check the solution given. may be possible question is wrongly posted !!!!

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