zachattack05 70 Posting Pro in Training

I have a string representing a date time, and a datetime local variable property. The string representing the datetime could be null or an empty string. To check for this, I thought I could check for a null or whitespace value and assign the appropriate value using this code:

ReturnValue.ArrivalDate = string.IsNullOrWhiteSpace(Screenings.ArrivalDate) ? null : DateTime.Parse(Screenings.ArrivalDate);

Pretty simple. The property ReturnValue.ArrivalDate is of the type DateTime?. So if the Screenings.ArrivalDate string is null or white space, it would assign the value null to the nullable ReturnValue.ArrivalDate property and if it's not null or whitespace, it would parse the string and return a DateTime object.

This line of code though produces this error:

Type of conditional expression cannot be determined because there is no implicit conversion between '' and 'DateTime'

The following code block though does work, it just looks horrible:

if (!string.IsNullOrWhiteSpace(Screenings.ArrivalDate))
    ReturnValue.ArrivalDate = DateTime.Parse(Screenings.ArrivalDate);
    ReturnValue.ArrivalDate = null;

Why does the ugly if/else work, but the nice single line (which, I would imagine compiles the same as the above if/else) is failing?

Good points rproffitt! The typical disaster plan here is unwritten and typically goes like this:

"Oh crap! There's a problem! Quick! Restore a backup!" Amazingly it works more often than I would care to admit.

Reverend Jim -- You mean something like this:


I'm literally in column index hell with this! There's even an obsolete message associated with the method used! It's making me crazy.

rproffitt commented: If this is so, can't delete columns yet. +14
zachattack05 70 Posting Pro in Training

I'm not sure if this is the right forum to ask this in, sorry if it isn't. It's been a while since I've been to this site.

We have a MS SQL database that contains a table with some columns that are no longer used (or shouldn't be). The data isn't updated anymore and has been moved to different columns to extend functionality with the applications that access the data.

Anyway, I would like to remove the columns, but I need to make sure that the ASP.NET website, an Access database and a C# WinForms application don't have any code that references these columns, lest there be an error with downtime to correct it.

I know it's a generic, and complicated question, but what are some suggestions on removing these columns safely while trying to prevent unforseen errors with the applications that access the table. Because there are 3 different applications, and some of them are rather complex, I'm worried that simply searching source code for references won't be enough to catch everything.

Any thoughts or ideas?

The % simply returns the remainder of the division of the first and second number.

So if i = 25, then 25 % 2 would return 5, which doesn't meet either of your if statements.

Change your code to this:

        Console.WriteLine("Problem #3 For loop - Add Up the Odds or Evens");
        Console.WriteLine("Please select 1 for the sum of even numbers or select 2 for sum of odd numbers");
        string usrin = Console.ReadLine();
        int usrinnum = int.Parse(usrin);
        int sumeven = 0;
        int sumodd = 0;
        int[] Numbers = new int[6] { 25, 26, 27, 28, 29, 30 };
        if (usrinnum == 1)
            foreach (int i in Numbers)
                if (i % 2 == 0)
                    sumeven += i;
                Console.WriteLine("The sum of the Evens is " + sumeven);
            foreach (int i in Numbers)
                if (i % 2 != 0)
                    sumodd += i;
                Console.WriteLine("The Sum of the odds is " + sumodd);

Read here:

Good idea!


zachattack05 70 Posting Pro in Training

I am working on a table that will hold batch data.

The table will have a BatchDate column as a DateTime type. I'm considering adding a column for BatchYear as an integer and BatchPeriod (which could be a week number, a month number or a quarter number) as an integer, even though both of these values can be derived from the BatchDate and using another column in the table.

I'm considering doing this because I'm thinking it would be easier to work with queries where someone doesn't have to pull the date from the table first, compute the period they want and then query the table again. Also, if someone is looking for a batch from the 3rd quarter of 2012, the server would have to convert each BatchDate to it's quarter equivalent and do the same for the year and then test for a match, but if the values are there in separate columns, one could simply query the BatchPeriod and the BatchYear column for a match.

Is this a bad idea to break normal form this way?

That stinks.

I was hoping they would fix it.

I'm assuming it isn't fixed in the latest version either?

zachattack05 70 Posting Pro in Training

I've asked this on SO AND Reddit without so much as a peep...was hoping DW would turn up the answer!

I have an ascx user control that has a custom event added to it.

I can get the event to work without problem, but the event doesn't show up in Visual Studio's property editor, only in intellisense. Is there an attribute I am missing or something?

The event definition is:

[Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
public event EventHandler<EventArgs> SelectedIndexChanged;

The event doesn't show up in the property box but all of my custom properties do:

But is accessable through intellisense:

Is there a way to have the events show up in the property editor?

Sorry for the late reply!

rproffitt, I don't see how it degrades the password. There are many zip cracking tools out there, true, but there are also many tools to brute force their way into http login forms as well. Passwords come with risks in general. Since the files are served over a HTTPS connection and are provided to those who download them, no one else should be able to access them and attempt to crack the zip password unless they have physical access to the downloader's machine. This isn't something I can protect against, regardless of the password.

pritaeas, I've toyed with the idea of doing that, but the drawback is that the user has to wait for the email to arrive and if it doesn't for whatever reason, then it can cause issues. I was hoping to have it be simple in that the user can just use the password they already know to open the files. The other disadvantage is that the password then could reside on email servers that could be used later to re-open the file.

I might just let them download it without a password and just keep the file unprotected. After all the connection is encrypted as well as the fact that the user has to login to download it to begin with. Once it's on their machine, security is out of my hands anyway.

I could, but I don't know what the passwords are.

They are stored in a one way hash.

zachattack05 70 Posting Pro in Training

The Membership table for our ASP.NET site has the encrypted passwords and password salts stored when a user logs in.

The site is already served over an HTTPS connection, but we would like to give our clients the ability to download and save certain files and documents. We would like to have those documents encrypted (essentially password protected), which we can do, but, we would like to have them be able to open those enrypted documents using the password they use to login to the site.

Is it possible to do this?

Essentially, I don't see how it would be difficult. We don't want to know the user's password, all we want is to essentially "wrap" the contents of a file in a shell (zip file or whatever) and when they open the file, the password they provide is checked against the embedded password and salt values and if they match, open, if not, don't. I'm just not sure if it's possible when encrypting a file, or password protecting it, to be able to say, essentially, "OK, password protect this file, here's the password that's already encrypted using XYZ algorythm. Don't encrypt it again, it already is."

Does this make sense?

I kinda figured I wouldn't be able to do it easily.

I think I'm just going to use a SP or view since I can check if a datetime field is null in a SQL Query and just convert that result to a bit field instead. The date is rather irrelevant for the report, all that's important is that a date is present or not.

Yay for moving business logic to a database...not. Ugh.

Thanks for your input rproffitt.


I don't think that will work. I probably should have explained more about the report.

Essentially the report contains a matrix of data, and two of those columns contain a gauge indicator control. The sql command selects a set of data from the table and the report (is supposed to) show a matrix similar to this:

Those checks and X images are based on whether or not a date is present or not. If it is, a check, if not, an X.

Two reports won't work simply because the report shows multiple records from the database.

zachattack05 70 Posting Pro in Training

Hi everyone!

I am in major need of some help here and before I go off and write a SP to handle this for me, I though I would ask here for advice first.

I am writing a report to display on our site using the ReportViewer component and the report editor in VS.

We have a SQL table that contains a DateTime field (two actually) and those fields also accept null values.

The report I am writing in ASP.NET needs to select the data from the table and determine if the DateTime field is null to show certain values on the report.

Some of the solutions I have found involve testing for DateTime.MinValue, but the problem is that some of the dates in the database legitimately have that value. So I can't check against that.

Is there a way, besides me creating a SP on the SQL server to check for NULL values, for me to do this?

Because I am using a report, my options for codebehind are rather limited. I have tried using the IsNothing() and IsDate() on the field, but it simply throws an error saying the report couldn't be processed.

Any thoughts?

zachattack05 70 Posting Pro in Training

Hi everyone!

So we have a web application that some of our clients use to manage their account. Part of that means they can manage activities that their registered employees do. Right now we have a table that logs all of a customer's employees activities, even if they don't use the web application.

We would like to add the ability to have our web application users add the outcome of the activity, notes, and other pieces of data (about 10 in total).

The problem is that not all of our customers use the app so they wouldn't be adding this data to our system, but instead would manage it with pencil and paper (old school style!) and even those that use the web app aren't required to enter this extra data, they can simply monitor the activities and still manage the outcomes with pencil and paper.

Given this, should I just add new fields to the existing table of activities even though a lot of them may end up being NULL values or should I use a lookup table and a 1-1 relationship?

My initial thought was to put the new fields in the existing table, (which has about 120,000 rows now and averages a growth of about 1,500 new records per month) but I don't know how many users will actually be adding the data in the future and I don't want to shoot myself in the foot. I'd rather design with the idea that the database is millions ...

Thanks for the help!


Thanks for the reply!

I don't necessarily want the scrollbar control itself to "fade". The scrollbar can always be visible, I was talking more on the lines of having the content itself "fade" at the bottom of the div tag. Like this:

zachattack05 70 Posting Pro in Training

On our site we have a "News and Information" section at the top of our landing page. Right now it looks like this:
I'd like to change this to look something like the image below, but I'm having a hard time figuring out how to do this, or if it's even possible?
I am using bootstrap CSS as much as possible, but I don't see anything like this in their documentation.
Any thoughts or ideas would be GREATLY appreciated!


I simply disabled the viewstate mode for the panel and it works fine now :)

zachattack05 70 Posting Pro in Training

Good afternoon everyone!

I'm running into a small snag and it could just be because it's late and I'm not thinking clearly.

I have an ASP Panel that is an alert box. The panel's initial visible property is set to false and should only be set to true when specific events happen and my ShowAlert(string message) method is called.
Everything works great except that when the page posts back the alert re-appears when it shouldn't. This is because the ShowAlert(string message) method sets the visible property to "true" but nothing ever sets it to false again.

The alert box can be dismissed when the user clicks the X button, but the problem is, I'm not sure how to use that click event to change the visible status of the panel. The other issue is since the alert isn't modal, the user can simply ignore the message and perform other events that cause a postpack, causing the message to stay.

Is there a way to essentially "show" a panel and then "hide" it the next time a postback occurs? I know I could check for a postback and just set the visible property to false, but if I do that it may prevent the alert from showing when it needs to show.

Confusing I'm sure.

Here's the HTML for my alert box:

<asp:Panel ID="PanelAlert" runat="server" CssClass="alert alert-warning alert-dismissible fade in" role="alert" data-spy="affix" Visible="False"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> 
    <asp:Literal ID="LiteralAlertMessage" runat="server"></asp:Literal>

and the method that shows the alert:

    /// <summary> ...

I haven't tried it no. The MembershipProvider class has quite a few methods and I can't really test it.

I guess actually I could try with just a generic class of my own. I was hoping someone here might know so I didn't have to spend time writing a abstract class, implementing it and testing it to see if it worked.

I'm just leaving them as is for now. I doubt the parameter names matter really, the signature is the same and is probably all that matters.

After I implement the entire provider I might try switching a parameter name and seeing what happens. But for now, I'll deal with the mismatched names...I guess that's what documentation is for eh? :P

zachattack05 70 Posting Pro in Training

If I implement an abstract class that contains this method:

    private void MyMethod(string awesomeParameter, int aBigNumber)
        // something cool happens here!
        throw new NotImplementedException();

can I change it to this without breaking the implementation?

private void MyMethod(string myParam, int myInt)
    // something cool happens here!
    throw new NotImplementedException();

I can't seem to find an answer to this, and I've never run into this issue before, but I'm implementing a new MembershipProvider and the default implementation uses some logical parameter names, but they don't match our sql table schema. For example, the implementation uses "username" but our table's column is "UserID." It would be easier to read through the code if the names matched the schema we are using.

Sorry for taking so long to respond, I've been very busy!

Thank you both so much for your help! You guys are the best!

zachattack05 70 Posting Pro in Training

I am writing a custom MembershipProvider for ASP.NET and would like to record certain events in a table when they happen.
I have the methods to do it, but I would like to get the value of the "ID" column of the row I insert into the table.

I have the following method (which is obviously incomplete), but I'm not sure if it will work and I'm not in a place where I can test it yet, so I thought I would ask if this appears to be a valid way of retreiving the RecordID value.

The SQL Query and the SqlCommand object are my biggest concern.

The command includes "OUTPUT Inserted.RecordID" which should work according to this. If the command is okay, then my concern is how to execute the command to read the returned value. I figured the ExecuteScalar() method is the best choice, but I wasn't completely sure what type of object is returned. Is it a row/column set or is it the literal value returned from the server where casting it as Int32 would work?

Anyway, suggestions? Comments? Ideas?

        private bool EventLog(int userNumber, int userID, UserEventTypes eventType, out int recordID)
            SqlConnection Conn = new SqlConnection(ConnectionString);
            SqlCommand EventCommand = new SqlCommand("INSERT INTO EventLog " +
            " (UserNumber, UserID, EventType, DateTime) OUTPUT Inserted.RecordID Values(?,?,?,?)", Conn);

            EventCommand.Parameters.Add("@UserNumber", SqlDbType.Int).Value = userNumber;
            EventCommand.Parameters.Add("@UserID", SqlDbType.NVarChar, 50).Value = userID;
            EventCommand.Parameters.Add("@EventType", SqlDbType.NVarChar, 50).Value = eventType.ToString();
            EventCommand.Parameters.Add("@DateTime", SqlDbType.DateTime).Value = DateTime.Now;


                Int32 EventRecordID = (Int32) EventCommand.ExecuteScalar();

                recordID = EventRecordID;
            catch (Exception) ...


I was only using validating user input as an example, but was more interested in the overall process of MVVM and how it is actually implemented.

Thanks for the info guys!

I think I'll try my hand at WPF. It's been a very agrivating day and I feel like I have accomplished...well...I made a blank VS solution and read a lot of documentation...

zachattack05 70 Posting Pro in Training

Forgive me, but I've only really used WinForms in the past, and MVVM and WPF are new to me.

For those who use MVVM with WPF, do you actually make separate directories (namespaces) for your Models, Views and ViewModels files or is it more of an abstract idea?

I fundamentally understand what the MVVM process does, I just don't completely understand how it is truely implemented. For example:

If we store our data in a SQL server, in a general respect, wouldn't that dataset be the Model? It certainly represents the data and how it is all related. A "model" so to speak of the data.
If a dataset is a Model, the ViewModel is where I lose all understanding. If the ViewModel interacts with the Model on behalf of the view, and (I imagine) does most of the business logic, how can that not be in the same class as the view? I mean, if I have a textbox that a user is supposed to enter an integer in, but instead types a string, how am I supposed to validate the input before it is sent to the Model unless I check the data when the user enters it (which is in the View, right?). I can't do this because if I use databinding (which is what WPF seems to be popular for), I don't get the oportunity to inspect the data entered. Would the ViewModel just be a class with event handlers to validate data and manipulate it? ...

zachattack05 70 Posting Pro in Training

I am starting a new application for our business to help maintain our client information, so it is going to be a very data driven application.

I'm curious, from the standpoint of those who have used both and who may have constructive suggestions on the future direction of development, should the application be written in WinForms (which I am much more familiar with) or WPF (which I have been avoiding like the plague...XAML sucks!)

Despite MY prejudice, I am willing to try to learn WPF and invest some time and money into it, but I would rather not if it is going to follow the same path as Silverlight and slowly fade away into the abyss of "well that was pointless to learn" list of application technologies.

I have read that WPF is great at making a "pretty" interface, but not so great at doing "simple" things that actually make the application work.

My problem, or rather, concern is that MS is going to slowly pull the plug on WinForms and replace it with WPF or some other technology and I'd rather not develop an application where the tools to update it and maintain it are going to slowly disappear.

I know no one can tell the future, but I'm curious what people think of the two different platforms and if you were starting a new, long term project, would you go with WPF or WinForms?

zachattack05 70 Posting Pro in Training

I know the site switched to a tag system, and while I personally don't care for it, I like the community too much to find an alternative.

Since I really only post to a single "tag" group, is it possible for people to have a favorite tags list we can create at the top of the screen? Scrolling to the bottom is a drag just for me to click "C#" and see relevant posts (relevant to me that is).

Just an idea. :)

zachattack05 70 Posting Pro in Training

Good afternoon fine DaniWeb folks!

I am about to pull my hair out on this one and I'd like to know if someone knows of a simple or obvious "gotcha!" for this problem.

I've got a form with some detail fields on it (below)

When a user attempts to navigate off of the record shown, a method called "Save" is called, which prompts the user if they wish to save the record before it is changed.

This is the text of that method (please forgive the rough code, it's very much a work in progress):

        /// <summary>
        /// Checks if changes have been made and saves those changes to the datasource.
        /// </summary>
        /// <param name="showPrompts">If True, shows a prompt to the user asking them to confirm changes if changes are found.
        /// If set to False, no prompts are shown.</param>
        /// <returns>True if the save operation completed. False if the operation was canceled.</returns>
        private bool Save(bool showPrompts)
            DialogResult savePrompt = System.Windows.Forms.DialogResult.Yes;

            if (ActiveAccountID == -1)
                createdDateTimePicker.Value = DateTime.Now;

                savePrompt = MessageBox.Show("Would you like to save your changes?", "Save", MessageBoxButtons.YesNoCancel);

                if (savePrompt == System.Windows.Forms.DialogResult.No)
                    return true;
                else if (savePrompt == System.Windows.Forms.DialogResult.Cancel)
                    return false;
            else if (dSDCDataSet.Accounts.FindByID(ActiveAccountID).HasVersion(DataRowVersion.Proposed))
                savePrompt = MessageBox.Show("Would you like to save your changes?", "Save", MessageBoxButtons.YesNoCancel);

                if (savePrompt == System.Windows.Forms.DialogResult.No)
                    return true;
                else if (savePrompt == System.Windows.Forms.DialogResult.Cancel)
                    return false;
                return true;

            lastUpdatedDateTimePicker.Value = DateTime.Now;

            // validate the form
            this.Validate(); ...