Solved

Unable to read data from SQL2005 in c#

Posted on 2008-06-13
6
208 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
  • 2
6 Comments
 
LVL 142

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now