Click here to Skip to main content
15,897,148 members
Home / Discussions / Database
   

Database

 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Rocky#17-Mar-08 6:18
Rocky#17-Mar-08 6:18 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Mark J. Miller17-Mar-08 6:34
Mark J. Miller17-Mar-08 6:34 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Rocky#17-Mar-08 6:46
Rocky#17-Mar-08 6:46 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Mark J. Miller17-Mar-08 6:56
Mark J. Miller17-Mar-08 6:56 
GeneralRe: Need to execute a very time consuming Stored procedure on a remote machine. Pin
Rocky#17-Mar-08 7:11
Rocky#17-Mar-08 7:11 
Questionavoiding 1/1/1900 in SQL SERVER? Pin
John Sundar14-Mar-08 23:03
John Sundar14-Mar-08 23:03 
GeneralRe: avoiding 1/1/1900 in SQL SERVER? Pin
Rocky#15-Mar-08 1:06
Rocky#15-Mar-08 1:06 
GeneralRe: avoiding 1/1/1900 in SQL SERVER? Pin
Mark J. Miller17-Mar-08 4:54
Mark J. Miller17-Mar-08 4:54 
If you have full control of the application's source code, a better solution than a Trigger would be to check the value in the application code for 1/1/1900. If it matches 1/1/1900, then set the parameter value for your SqlParameter object to DbNull.Value instead of the actual datatime value. If you aren't using SqlParameter objects (which you should be) then set the value of the string to "NULL".

Example 1:

<br />
using(SqlCommand cmd = new SqlCommand(.. set ctor arguments ..)){<br />
  // setup cmd object<br />
<br />
  cmd.Properties.Add("@date", SqlDbType.DateTime);<br />
  if(myDateVariable.ToShortDateString() == "1/1/1900")<br />
    cmd.Properties["@date"] = DbNull.Value;<br />
  else<br />
    cmd.Properties["@date"] = myDateVariable;<br />
}<br />


Example 2:

<br />
StringBuilder sql = new StringBuilder("INSERT INTO myTable(dateColumn) VALUES(");<br />
if(myDateVariable.ToShortDateString() == "1/1/1900")<br />
  sql.Append("NULL");<br />
else<br />
  sql.Append(String.Format("'{0}'", myDateVariable));<br />


NOTE: The second example will expose you to Sql Injection attacks if the value you are concatenating to your SQL statement is a String variable, so I recommend the first method for all SQL statements.


GeneralBest Practice: Connection Strings to MS-SQL datasource from web application Pin
Leo Smith14-Mar-08 9:18
Leo Smith14-Mar-08 9:18 
GeneralRe: Best Practice: Connection Strings to MS-SQL datasource from web application Pin
Mark J. Miller17-Mar-08 5:07
Mark J. Miller17-Mar-08 5:07 
GeneralStoring Compressed Image Into SQL Server Pin
abdurrahman oğuz14-Mar-08 6:30
abdurrahman oğuz14-Mar-08 6:30 
GeneralRe: Storing Compressed Image Into SQL Server Pin
Rob Philpott14-Mar-08 6:38
Rob Philpott14-Mar-08 6:38 
GeneralRe: Storing Compressed Image Into SQL Server [modified] Pin
abdurrahman oğuz14-Mar-08 22:40
abdurrahman oğuz14-Mar-08 22:40 
GeneralRe: Storing Compressed Image Into SQL Server Pin
Mark Churchill16-Mar-08 1:57
Mark Churchill16-Mar-08 1:57 
Generalinsert user checkboxlist selections in table Pin
C. L. Phillip14-Mar-08 4:26
C. L. Phillip14-Mar-08 4:26 
GeneralRe: insert user checkboxlist selections in table Pin
Mark J. Miller14-Mar-08 6:28
Mark J. Miller14-Mar-08 6:28 
GeneralRe: insert user checkboxlist selections in table Pin
C. L. Phillip14-Mar-08 9:36
C. L. Phillip14-Mar-08 9:36 
GeneralPlease help me move these records to another table... Pin
Support12314-Mar-08 3:10
Support12314-Mar-08 3:10 
GeneralRe: Please help me move these records to another table... Pin
soni uma14-Mar-08 3:20
soni uma14-Mar-08 3:20 
GeneralRe: Please help me move these records to another table... Pin
Support12314-Mar-08 3:23
Support12314-Mar-08 3:23 
GeneralRe: Please help me move these records to another table... Pin
soni uma14-Mar-08 3:26
soni uma14-Mar-08 3:26 
GeneralRe: Please help me move these records to another table... Pin
Support12314-Mar-08 3:25
Support12314-Mar-08 3:25 
GeneralFetching records based on Boolean operators Pin
sumit703414-Mar-08 0:41
sumit703414-Mar-08 0:41 
GeneralRe: Fetching records based on Boolean operators Pin
GDMFSOB14-Mar-08 0:48
GDMFSOB14-Mar-08 0:48 
GeneralRe: Fetching records based on Boolean operators Pin
sumit703414-Mar-08 0:55
sumit703414-Mar-08 0:55 

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.