Click here to Skip to main content
15,888,984 members
Home / Discussions / C#
   

C#

 
GeneralRe: Uploading a large Excel file using Entity Framework and Stored Procedure Call Pin
Dave Kreskowiak1-Oct-18 4:20
mveDave Kreskowiak1-Oct-18 4:20 
GeneralRe: Uploading a large Excel file using Entity Framework and Stored Procedure Call Pin
Member 140028821-Oct-18 11:27
Member 140028821-Oct-18 11:27 
GeneralRe: Uploading a large Excel file using Entity Framework and Stored Procedure Call Pin
simpledeveloper1-Oct-18 13:30
simpledeveloper1-Oct-18 13:30 
GeneralRe: Uploading a large Excel file using Entity Framework and Stored Procedure Call Pin
Dave Kreskowiak1-Oct-18 15:52
mveDave Kreskowiak1-Oct-18 15:52 
GeneralRe: Uploading a large Excel file using Entity Framework and Stored Procedure Call Pin
simpledeveloper2-Oct-18 7:58
simpledeveloper2-Oct-18 7:58 
GeneralRe: Uploading a large Excel file using Entity Framework and Stored Procedure Call Pin
Dave Kreskowiak2-Oct-18 10:04
mveDave Kreskowiak2-Oct-18 10:04 
QuestionHow to allow null value inside datetime Pin
thepast27-Sep-18 2:54
thepast27-Sep-18 2:54 
AnswerRe: How to allow null value inside datetime Pin
OriginalGriff27-Sep-18 4:19
mveOriginalGriff27-Sep-18 4:19 
There are a couple of things here:
1) Text boxes don't contain NULL values - they can contain empty strings, but that is a very different thing.
2) ParseExact will fail if the string doesn't match - which means you must either use a try...catch block, or better use TryParseExact instead, reporting a problem to the user instead of trying to pass anything to the DB.
3) What you show won't work: even if it did what you think, it would pass the string version to SQL via concatenation, and that really should be avoided as it makes SQL convert the string back to a DateTime and that can introduce errors.

So verify the TB at the start of the method, and pass DateTime or NULL like this:
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand cmd = new SqlCommand("INSERT INTO myTable (startDate) VALUES (@SD)", con))
        {
        object o;
        if (string.IsNullOrWhitespace(Startdate.text)) o = DbNull.Value;
        else o = valueConvertedToDateTimeEarilerWhenYouValidatedIt;
        cmd.Parameters.AddWithValue("@SD", o);
        cmd.ExecuteNonQuery();
        }
    }

Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

QuestionHow to do server side pagination and searching in bootstrap table Pin
Member 1148667427-Sep-18 2:26
Member 1148667427-Sep-18 2:26 
AnswerRe: How to do server side pagination and searching in bootstrap table Pin
Richard Deeming28-Sep-18 1:11
mveRichard Deeming28-Sep-18 1:11 
Questionstudent's concern Pin
Member 1399919126-Sep-18 20:44
Member 1399919126-Sep-18 20:44 
AnswerRe: student's concern Pin
OriginalGriff26-Sep-18 21:01
mveOriginalGriff26-Sep-18 21:01 
AnswerRe: student's concern Pin
Richard MacCutchan26-Sep-18 21:16
mveRichard MacCutchan26-Sep-18 21:16 
PraiseRe: student's concern Pin
Maciej Los26-Sep-18 21:44
mveMaciej Los26-Sep-18 21:44 
GeneralRe: student's concern Pin
Richard MacCutchan26-Sep-18 21:56
mveRichard MacCutchan26-Sep-18 21:56 
Questionftp: change directory Pin
Baumimann26-Sep-18 7:20
Baumimann26-Sep-18 7:20 
AnswerRe: ftp: change directory Pin
Richard Deeming26-Sep-18 7:24
mveRichard Deeming26-Sep-18 7:24 
QuestionWindows notification program as a answer program in c# wpf Pin
Teun van den Broek26-Sep-18 1:27
Teun van den Broek26-Sep-18 1:27 
AnswerRe: Windows notification program as a answer program in c# wpf Pin
OriginalGriff26-Sep-18 2:20
mveOriginalGriff26-Sep-18 2:20 
AnswerRe: Windows notification program as a answer program in c# wpf Pin
ZurdoDev26-Sep-18 2:58
professionalZurdoDev26-Sep-18 2:58 
AnswerRe: Windows notification program as a answer program in c# wpf Pin
Dave Kreskowiak26-Sep-18 5:52
mveDave Kreskowiak26-Sep-18 5:52 
GeneralXML file comparison output with node names Pin
Raja Saravanan25-Sep-18 5:08
Raja Saravanan25-Sep-18 5:08 
GeneralRe: XML file comparison output with node names Pin
Dar Brett25-Sep-18 5:26
Dar Brett25-Sep-18 5:26 
GeneralRe: XML file comparison output with node names Pin
Raja Saravanan25-Sep-18 18:09
Raja Saravanan25-Sep-18 18:09 
GeneralRe: XML file comparison output with node names Pin
Mycroft Holmes25-Sep-18 18:59
professionalMycroft Holmes25-Sep-18 18:59 

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.