Solved

Unable to read data from SQL2005 in c#

Posted on 2008-06-13
6
207 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]
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

19 Experts available now in Live!

Get 1:1 Help Now