Showing posts with label default. Show all posts
Showing posts with label default. Show all posts

Friday, March 30, 2012

passing or defaulting null

I wanted to know what are the advantages/divantages of passing null value
s
in the sp as oppose to setting them as default in the tables.
I am using SQL 2005, "set ANSI_NULLS ON".
ThanksMumbai_Chef wrote:
> I wanted to know what are the advantages/divantages of passing
> null values in the sp as oppose to setting them as default in the
> tables.
> I am using SQL 2005, "set ANSI_NULLS ON".
>
If you have, for example, a DateEntered column, which will always need to be
initialized to the current date and time when a row is inserted and never
subsequently updated, then by all means create a default constraint for the
column. This allows you to never even have to mention the column in any
UPDATE/INSERT DML queries, and as a result, you never have to declare a
parameter for this columns value in any of your procedures.
On the other hand, if you have a column for which you will sometimes be
providing a non-default value, then obviously you will need to include a
parmaeter for that value in your stored procedures. Whether or not you
declare the parameter with a default value (making it an optional parameter)
is totally up to you.
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

passing null date value to database

how can i pass null value to database? date is not required field in my database. i can pass default date but i think default date is not good in my case as it is DOB of a customer.Hi there,

Check out the DBNull class. :)|||DBNull.Value should do the trick ...
But don't forget when reading back from the table to check for the NULL value|||well, i tried that it says can't convert System.DBNull to datetime. i also used Convert.DBNull but it shows error at run time if the value isn't provided. well, it seems like i have to pass DBNull.Value directly but in my case i have to assign it to variable coz i am using stored procedure and using SqlHelper class.

what about integers though? is it the same thing?|||I think you should be able to use System.Data.SqlTypes.SqlDateTime.Null.

Terri|||hi terri,
it still says "value of type System.Data.SqlTypes.SqlDateTime.Null cannot be converted to 'Date'"|||Can you please post the relevant code?

Terri|||


Dim commDate As DateTime

If tbCommDate.Text = "" Then
'commDate = New DateTime(1900, 1, 1)

'can't use this statement
commDate = System.Data.SqlTypes.SqlDateTime.Null
Else
commDate = CType(tbCommDate.Text, DateTime)
End If

I pass this "commDate" to the stored procedure. i am using SQLHelper class.|||We need to also see the code where you are telling the SQLHelper class the data type of the commDate parameter.

Terri|||


Public Shared Function ProspectiveInsert(ByVal agentId As Integer, ByVal tripId As Integer, ByVal institution As String, ByVal nationality As String, ByVal title As String, ByVal dob As DateTime, ByVal sex As String, ByVal elicos As String, ByVal course1 As String, ByVal course2 As String, ByVal fname As String, ByVal mname As String, ByVal lname As String, ByVal osStud As Boolean, ByVal osAdd As String, ByVal osPhone As String, ByVal osMobile As String, ByVal osFax As String, ByVal osSuburb As String, ByVal osPostcode As String, ByVal osCity As String, ByVal osCountry As String, ByVal add As String, ByVal phone As String, ByVal mobile As String, ByVal fax As String, ByVal suburb As String, ByVal postcode As String, ByVal city As String, ByVal country As String, ByVal email As String, ByVal ugQual As String, ByVal ugIns As String, ByVal ugYear As String, ByVal seconQual As String, ByVal seconYear As Integer, ByVal seconIns As String, ByVal pgQual As String, ByVal pgIns As String, ByVal pgYear As Integer, ByVal appStatus As String, ByVal appNotes As String, ByVal appDate As String, ByVal ielts As Double, ByVal engRemarks As String, ByVal coeDate As DateTime, ByVal coeRemarks As String, ByVal offerDate As DateTime, ByVal offerRemarks As String, ByVal recAddDate As DateTime, ByVal prefCommDate As DateTime, ByVal notes As String, ByVal modBy As String) As Integer

Try
SqlHelper.ExecuteNonQuery(ConfigurationSettings.AppSettings("connectionString"), "MCS_ProspectiveStudentInsert", agentId, tripId, institution, nationality, title, dob, sex, elicos, course1, course2, fname, mname, lname, osStud, osAdd, osPhone, osMobile, osFax, osSuburb, osPostcode, osCity, osCountry, add, phone, mobile, fax, suburb, postcode, city, country, email, ugQual, ugIns, ugYear, seconQual, seconIns, seconYear, pgQual, pgIns, pgYear, appStatus, appNotes, appDate, ielts, engRemarks, coeDate, coeRemarks, offerDate, offerRemarks, recAddDate, prefCommDate, notes, modBy)
Catch ex As SqlException
Return ex.Number
End Try

Return 0
End Function


This is the function where I have passed the dates but i can't assign the System.Data.SqlTypes.Null to date variable.|||OK, I believe I have misled you. You should be using System.DBNull. Let us know if this works better for you.

Terri|||it says "DBNull is a type in system and can't be used as an expression."

at the moment i am using default value but i think that's not a good idea is it?|||thanx a lot for your time Terri.
i appreciate your willingness to help me.|||THe problem has NOTHING to do with SQL. See:

[code]
Dim commDate As DateTime

If tbCommDate.Text = "" Then

'commDate = New DateTime(1900, 1, 1)

'can't use this statement

commDate = System.Data.SqlTypes.SqlDateTime.Null
[/code]

NATURALLY blows. You can not assign SqlDateTime.Null to a DateTime.

You have to make the assignment "lower" - i.e. you pass the SqlDateTime directly into the relevant SQL parameter. You can not store it in another non-compatible time in the meantime.

For example, the EntityBroker - my O/R-Mapper - makes the switch statement directly when putting the value into the PARAMETER (or encoding the value for the SQL string). THEN it gets accepted (DBNull.Value, btw.). The way you do it earlier just results in an invalid cast.|||but i am using SqlHelper class. so i think i can't use it then. right?

Monday, March 26, 2012

Passing in a default parameter date via a URL

Hi Guys,

What is the syntax for passing in a default parameter of current date via a URL.

cheers

If you don't want to have to deal with IFormatProvider and DateTimeStyles of DateTime.Parse() method, then you can simply use the "MM/dd/yyyy" format. For example:

string dateToConvert = "12/25/2006";
DateTime today = DateTime.Parse(dateToConvert);

So, in your url, simply do: myPage.aspx?date=12/25/2006

Then retrieve the query string (Request.QueryString["date"]), check to make sure it's not null and not empty, and then finally convert it using the above mentioned DateTime.Parse(...).|||

Thanks jcasp.

This isn't quite what I meant. I want the currentdate to be passed in which I do not know of beforehand. Usually in VB I use Now or Date what is the equivalent.

Cheers

|||

Hi,

you can use DateTime.Now in .NET.

Grz, Kris.

Friday, March 23, 2012

Passing default parameters

I have created some reports for our school district and would like to make a
2nd parameters default to what matches the 1st parameter in a drop down list.
Example:
If a teacher selects their school from the parameter drop down listing,
what I am trying to do is so that the teacher does not have to type in their
name and ensure the sysntex is correct, but to have the 2nd parameter default
to all teachers in that school so they could choose from the listing.
I've tried using the school and the teachers in a seperate dataset but when
I then select on the school it shows the school multiple times for each
teacher. I just want the school to appear for it's parameter then the 2nd
parameter would be populated with the teachers names based on the school
selected.
Thanks in Advance
--
Wayne HessThe second parameter should be based on a dataset that accepts the school
and returns the list of teachers.
select distinct firstname + ' ' + lastname as label, teacherid as value from
from schoolteachertable where school = @.SchoolParam
Use this as the source for the second parameter.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Wayne" <Wayne@.discussions.microsoft.com> wrote in message
news:9CB415ED-7050-4073-BACD-836545F0F0E6@.microsoft.com...
>I have created some reports for our school district and would like to make
>a
> 2nd parameters default to what matches the 1st parameter in a drop down
> list.
> Example:
> If a teacher selects their school from the parameter drop down listing,
> what I am trying to do is so that the teacher does not have to type in
> their
> name and ensure the sysntex is correct, but to have the 2nd parameter
> default
> to all teachers in that school so they could choose from the listing.
> I've tried using the school and the teachers in a seperate dataset but
> when
> I then select on the school it shows the school multiple times for each
> teacher. I just want the school to appear for it's parameter then the 2nd
> parameter would be populated with the teachers names based on the school
> selected.
> Thanks in Advance
> --
> Wayne Hess

Friday, March 9, 2012

passing a boolean parameter to a package

hello at everybody well i have a problem. with in a package i defined a bollean variable with the name "x" and with a default value FALSE.

i created a configuaration file that contains the variable "x" as [user::x]. when i deploy the package to a server and i try to execute the package putting to the set values TRUE fror the x variable it doesnt work.

what can i do?

thnxs

kats wrote:

hello at everybody well i have a problem. with in a package i defined a bollean variable with the name "x" and with a default value FALSE.

i created a configuaration file that contains the variable "x" as [user::x]. when i deploy the package to a server and i try to execute the package putting to the set values TRUE fror the x variable it doesnt work.

what can i do?

thnxs

Boolean values are either 0 or 1. Not True or False. True or False is a presentation layer feature. Pass in a 0 for false or a 1 for true and things should work just fine.

Wednesday, March 7, 2012

Pass sysdate value to Global Variable

Hi,

How can we pass sysdate value as default value to a GlobalVariable to SSIS?

Regards,

Mohammad Sufian

Create global variable.

Set "EvaluateAsExpression" to true in the properties list for that variable.

In the expression box, type in "getdate()"

Saturday, February 25, 2012

Pass a parameter to an url in the default webbrowser

hi

i would like to launch an crystal report file from my vb.net program. This report has 1 parameter field (ID). I would like to give this parameter directly in the URL.

at the moment i use something like this but the parameterwindow still appears.

System.Diagnostics.Process.Start("http://Server/Reports/Report.rpt?ID="&Id)

anyone has a solution?

tnx in advance!
GeertI think there is method to suppress parameterwindow
If there is method like enablepopupmenu then set it to false|||tnx but will supressing the window pass the value? i believe not...

or is there a workaround this problem? like loading the report en then export it?