• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Unable to read data from SQL2005 in c#

Hi -This is my first posting on this website, I like this site as I see valuable answers which are useful to all irrespective of what they do.Ok, here's my question:

1. I have form1 that takes customer info and generates some ID . form1 details are sent to tickets table in SQL 2005 DB. Tickets: status,description,ID, Title are columns.
2. I have ASPX page that displays data grid retrieving values from the Tickets table. In sense :
Title - update-close .Here update and close takes us to some other pages where the parameter passed is ID.
3. Question is : If i click on Title on datagrid it should display me a page with status/description/Title if the parameter I pass is same as ID in the Tickets table
Unable to read the data using Data reader on landing page;
code is:
 protected void Page_Load(object sender, EventArgs e)

        String conn = "Server=IE;uid=ss;pwd=~~Ple;database=D;";
        String comm = "SELECT sStatus FROM Tickets WHERE folderID = '@FolderID'";
        SqlConnection myconn = new SqlConnection(conn);
        SqlCommand mycomm = new SqlCommand(comm, myconn);
        SqlDataAdapter a = new SqlDataAdapter(mycomm);
                DataSet s = new DataSet();
        SqlParameter SqlPar;
        SqlPar = mycomm.Parameters.Add("@FolderID", SqlDbType.VarChar, 50);
        SqlPar.Value = Request.QueryString["FolderID"].ToString();
        SqlDataReader SqlRea = mycomm.ExecuteReader();
        if (SqlRea.Read())


  • 2
1 Solution
Guy Hengel [angelIII / a3]Billing EngineerCommented:
        String comm = "SELECT sStatus FROM Tickets WHERE folderID = '@FolderID'";

        String comm = "SELECT sStatus FROM Tickets WHERE folderID = @FolderID ";

the quotes are bad, as with variables, if quotes are needed, the Sqlparameter will handle that.
sushmithaaAuthor Commented:
I got a solution for this like here:

The problem was not mainly because of the sql command, it was because of this:

 I had Console.WriteLine(SqlRea.GetString(0)); which should be

I did have the SQL statement changed but that didnt turn to be a solution. Anyways I thank you very much for the prompt response. I wanted to post this comment just so this might be useful for anyone else.

sushmithaaAuthor Commented:
may be my question wasnot clear but the answer i got in this site wasnt right one. i did post my answer too so it may be useful for other in case.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now