• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • 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);
        myconn.Open();
                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())
         Console.WriteLine(SqlRea.GetString(0));

              myconn.Close();

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

correct:
        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.
0
 
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
 Console.WriteLine(SqlRea.GetString(0).Trim());

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.
             

0
 
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.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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