0

basically i would like to add up the total size of all the files for a particular user and display it in a label...this is what i have so far:

SqlConnection myConnection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\ASPNETDB.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True");


            myConnection.Open();

            SqlCommand myFileCommand = new SqlCommand("SELECT SUM (fileSize) FROM aspnet_Files WHERE fileOwner = '" + this.User.Identity.Name + "'", myConnection);

            myFileCommand.ExecuteNonQuery();

           lblTotalSpaceUsed.Text = >>>result of the sql statement here?<<<

            myConnection.Close();

just wondering how you set the label text to the result of the sql statement, thanks for help

regards

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by julseypart
0

Use execute scalar as it returns the value of first row of the first column of the result set like so:

string result =  (string) myFileCommand.ExecuteScalar();
lblTotalSpaceUsed.Text = result;
0

um..

System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'.

how can i convert the database fileSize of type "int" to string??

0

k i just solved it with:

Int32 result =  (Int32) myFileCommand.ExecuteScalar();

lblTotalSpaceUsed.Text = result.ToString();

thanks again for the help ;)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.