Click here to Skip to main content
16,010,392 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: sql question Pin
AprNgp15-Aug-08 7:50
AprNgp15-Aug-08 7:50 
AnswerRe: sql question Pin
metallica_rock1017-Aug-08 23:35
metallica_rock1017-Aug-08 23:35 
Questiongrid view in asp.net using c# Pin
UD(IA)15-Aug-08 3:33
UD(IA)15-Aug-08 3:33 
AnswerRe: grid view in asp.net using c# Pin
Rutvik Dave15-Aug-08 4:06
professionalRutvik Dave15-Aug-08 4:06 
Questionpick and show starting text in asp.net from database Pin
dream_liner_7e715-Aug-08 3:32
dream_liner_7e715-Aug-08 3:32 
AnswerRe: pick and show starting text in asp.net from database Pin
eyeseetee15-Aug-08 3:35
eyeseetee15-Aug-08 3:35 
AnswerRe: pick and show starting text in asp.net from database Pin
Rutvik Dave15-Aug-08 4:18
professionalRutvik Dave15-Aug-08 4:18 
QuestionSystem.InvalidOperationException : Please help Pin
AprNgp15-Aug-08 2:36
AprNgp15-Aug-08 2:36 
I am reading some data from the database, but its giving System.InvalidOperationException:
my code is as follows :
LoadInfo l = new LoadInfo();
l.LoadFromSQL(Session["username"].ToString());

the class LoadInfo has the member function LoadFromSQL as follows,
public void LoadFromSQL(string username)
   {
       SqlDataReader reader = null;
       reader = SqlMember.ExecuteReader("SELECT UserId FROM Members WHERE UserName=@username", username);
       m.LoadFromReader(reader);
   }

the SqlMember class has the static member function ExecuteReader as following:
static public SqlDataReader ExecuteReader(string qs,string username)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand cmd = new SqlCommand(qs, conn);
        cmd.Parameters.Add(new SqlParameter ("@username","a"));
        conn.Open();
        if (cmd.ExecuteScalar() == null)
        {
            int i;
            i = 0;
        }
        return cmd.ExecuteReader();
    }

the LoadFromReader member function of SqlMember class is as follows:
public void LoadFromReader(SqlDataReader reader)
    {
        this.UserId = (int)reader["UserId"];
        this.FirstName = (string)reader["FirstName"];
        this.LastName = (string)reader["LastName"];
        this.CityId = (int)reader["CityId"];
        this.CountryId = (int)reader["CountryId"];
        this.Mood = (byte)reader["Mood"];
    }


The exception is occurring in the above function, while reading the data from the reader
this.UserId = (int)reader["UserId"];
if this line is commented (//) the exception occurs in the next line.
Error:
Invalid attempt to read when no data is present.
Confused | :confused:
The username provided by the session object is available in the database.
Please help me to solve this problem. Frown | :(
Is there any way to know, if the ExecuteReader returned any values ?

Apurv

AnswerRe: System.InvalidOperationException : Please help Pin
Rutvik Dave15-Aug-08 4:27
professionalRutvik Dave15-Aug-08 4:27 
GeneralRe: System.InvalidOperationException : Please help Pin
AprNgp15-Aug-08 5:35
AprNgp15-Aug-08 5:35 
GeneralRe: System.InvalidOperationException : Please help Pin
AprNgp15-Aug-08 7:44
AprNgp15-Aug-08 7:44 
Question'The underlying connection was closed: The connection was closed unexpectedly.' Error Pin
pubududilena15-Aug-08 1:15
pubududilena15-Aug-08 1:15 
AnswerRe: 'The underlying connection was closed: The connection was closed unexpectedly.' Error Pin
AhsanS15-Aug-08 1:18
AhsanS15-Aug-08 1:18 
GeneralRe: 'The underlying connection was closed: The connection was closed unexpectedly.' Error Pin
pubududilena15-Aug-08 1:31
pubududilena15-Aug-08 1:31 
GeneralRe: 'The underlying connection was closed: The connection was closed unexpectedly.' Error Pin
AhsanS15-Aug-08 1:44
AhsanS15-Aug-08 1:44 
Questionusing javascript frameworks with Asp.Net Pin
Boro_Bob15-Aug-08 1:08
Boro_Bob15-Aug-08 1:08 
AnswerRe: using javascript frameworks with Asp.Net Pin
RichardGrimmer15-Aug-08 4:39
RichardGrimmer15-Aug-08 4:39 
QuestionUsing "aspnet_regiis.exe -ga" on the basis of SID instead of "user name" Pin
Mushtaque Nizamani15-Aug-08 0:19
Mushtaque Nizamani15-Aug-08 0:19 
QuestionSSL Pin
mehrdadc4815-Aug-08 0:12
mehrdadc4815-Aug-08 0:12 
AnswerRe: SSL Pin
Manas Bhardwaj15-Aug-08 0:18
professionalManas Bhardwaj15-Aug-08 0:18 
GeneralRe: SSL Pin
mehrdadc4815-Aug-08 0:25
mehrdadc4815-Aug-08 0:25 
GeneralRe: SSL Pin
AhsanS15-Aug-08 0:37
AhsanS15-Aug-08 0:37 
GeneralRe: SSL Pin
eyeseetee15-Aug-08 0:41
eyeseetee15-Aug-08 0:41 
AnswerRe: SSL Pin
N a v a n e e t h15-Aug-08 6:11
N a v a n e e t h15-Aug-08 6:11 
AnswerRe: SSL Pin
JimmyRopes16-Aug-08 7:40
professionalJimmyRopes16-Aug-08 7:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.