Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 Page has no output

View previous topic View next topic Go down 
AuthorMessage
Scars
Member
Member
avatar

Posts : 16
Join date : 2011-03-09

Page has no output Empty
PostSubject: Page has no output   Page has no output EmptyWed May 11, 2011 11:22 pm

Hi! I need help about this one:
What I should do:
-I need to get the last login date of the user.

Problem:
The program does not give any date or error that's why I don't know what really happen.

sample code:

if (Session["logon"] != null){
if ((sqlConn.State == ConnectionState.Closed))
{
sqlConn.Open();
}
string logs = string.Empty;
string strCn = string.Empty;
string _dt = string.Empty;
string ndt = _dt;
DataSet ds1 = new DataSet("logs");
int badge = mylib.getBadgeNo(Page.User.Identity.Name.Remove(0, 9).ToString());
strCn = "select max(dt) as logs from logs where usr_badge_no='"+ badge +"'";
mylib.InitDataset(strCn, ds1);
//if (ds1.Tables[0].Rows.Count != 0){

_dt = ds1.Tables[0].Rows[0]["logs"].ToString();
//}
_dt = ndt;
lbllstlogin.Text = ndt; //this is a label where the last login date should be place
}
Back to top Go down
DeathMatch
Member
Member
avatar

Posts : 6
Join date : 2011-03-26

Page has no output Empty
PostSubject: Re: Page has no output   Page has no output EmptyWed May 11, 2011 11:23 pm

I'm not entirely sure what's happening inside your code there, but I can speculate(or guess) that mylib.InitDataset(...) runs the given SQL query on some DB and puts the data returned into DataTable ds1.Tables[0]? Something like that? If so, that seems kind of a strange way of doing that. If you're going that route, at least have the InitDataset method return either a DataTable or the actual String value which you're later trying String _dt to. Maybe that's the problem?

In any case, surround your code with a try..catch. Inside the catch, do a Response.Write on the exception message (http://msdn.microsoft.com/en-us/libr...n.message.aspx)

But even before you do that, run the SQL manually on the DB and see what you get.

Back to top Go down
Scars
Member
Member
avatar

Posts : 16
Join date : 2011-03-09

Page has no output Empty
PostSubject: Re: Page has no output   Page has no output EmptyWed May 11, 2011 11:25 pm

Okay, let's say that your SQL statement produces 1 row and value of column [logs] is what you need to put into label MyLabel. You can* do it this way. And I say can* because:
#1. There are various ways of doing this and this is only an example.
#2. Sometimes another guy comes along and says "oh no, don't do it this way, do it my way...my way is better...bla bla bla". No, at this point, your goal is not to look for which way is better, but to familiarize yourself with all the common approaches because once you know this, then you can make your own decision as to which way is better. So, to start, just read about the objects you see below (SqlConnection, SqlCommand, SqlDataReader). Also read about using the try..catch statement, and using{...}, which is basically a neat way of automatically doing garbage collection (a feature of C#). After that, read about binding data to data controls.

Label control:
Code:

.
.
.
<asp:Label ID="MyLabel" runat="Server" />
.
.
.

Codebehind:

Code:

using System.Data.SqlClient;
.
.
.
try
{
  using (SqlConnection mySqlConnection = new SqlConnection("<my Connection String>"))
  {
      mySqlConnection.Open();
      using (SqlCommand mySqlCommand = new SqlCommand("<my sql statement>", mySqlConnection))
      {
        mySqlCommand.CommandType = CommandType.Text;
        using (SqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader())
        {
            if (mySqlDataReader.HasRows)
       {
              mySqlDataReader.Read();
              MyLabel.Text = mySqlDataReader["logs"].ToString();
            }
        }
      }
      mySqlConnection.Close();        
  }
}
catch(Exception ex)
{
  Response.Write(ex.Message);
}
.
.
.
Back to top Go down
DeathMatch
Member
Member
avatar

Posts : 6
Join date : 2011-03-26

Page has no output Empty
PostSubject: Re: Page has no output   Page has no output EmptyWed May 11, 2011 11:25 pm

okey thanks... I just want to ask what does "exception" really means?? it makes me confused...because when i tried to read about try and catch it talks more about exception and i don't know what that really means... I mean.. what are the values that you can have "exception"? when do we need to use exception??
Back to top Go down
Sponsored content




Page has no output Empty
PostSubject: Re: Page has no output   Page has no output Empty

Back to top Go down
 

Page has no output

View previous topic View next topic Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: Page has no output Edit-trash Useless :: Trash-