Solved

Unable to read data from SQL2005 in c#

Posted on 2008-06-13
6
212 Views
Last Modified: 2012-05-05
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
Comment
Question by:sushmithaa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21782914
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
 

Accepted Solution

by:
sushmithaa earned 0 total points
ID: 21794574
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
 

Author Comment

by:sushmithaa
ID: 21816037
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question