|
 |
aspx thread: How to insert into SQL Null value?
Message #1 by "Pavel Hromadka" <hromadka@a...> on Wed, 14 Feb 2001 03:21:57 +0100
|
|
I have this code for insert a new member into database. All work fine,
but field BirthDate isn't requsted. If users don't fill birthDate how to
I may insert NULL value? Help me someone?
My code is there:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
SQLConnection Conn =3D new SQLConnection(SQL_CONNECTION_STRING);
SQLCommand myCommand =3D new SQLCommand("exec sp_AddMember
@UserName, @UserPassword, @Attributes, " +
" @Email, @FirstName,
@LastName, " +
" @BirthDate, @icqNumber",
Conn);
=09
myCommand.Parameters.Add(new SQLParameter("@UserName",
SQLDataType.VarChar, 15));
myCommand.Parameters["@UserName"].Value =3D UserName;
=09
myCommand.Parameters.Add(new SQLParameter("@UserPassword",
SQLDataType.VarChar, 10));
myCommand.Parameters["@UserPassword"].Value =3D UserPassword;
=09
myCommand.Parameters.Add(new SQLParameter("@Attributes",
SQLDataType.Int));
myCommand.Parameters["@Attributes"].Value =3D Attributes;
myCommand.Parameters.Add(new SQLParameter("@Email",
SQLDataType.VarChar, 150));
myCommand.Parameters["@Email"].Value =3D Email; =09
=09
myCommand.Parameters.Add(new SQLParameter("@FirstName",
SQLDataType.VarChar, 50));
myCommand.Parameters["@FirstName"].Value =3D FirstName;
=09
myCommand.Parameters.Add(new SQLParameter("@LastName",
SQLDataType.VarChar, 50));
myCommand.Parameters["@LastName"].Value =3D LastName;
=09
if (BirthDate !=3D DateTime.Empty) { =09
myCommand.Parameters.Add(new SQLParameter("@BirthDate",
SQLDataType.DateTime));
myCommand.Parameters["@BirthDate"].Value =3D BirthDate;
} else {
myCommand.Parameters.Add(new SQLParameter("@BirthDate",
SQLDataType.DateTime));
myCommand.Parameters["@BirthDate"].Value =3D DateTime.Empty;
}
=09
myCommand.Parameters.Add(new SQLParameter("@icqNumber",
SQLDataType.VarChar, 50));
myCommand.Parameters["@icqNumber"].Value =3D icqNumber;
=09
myCommand.ActiveConnection.Open();
myCommand.ExecuteNonQuery();
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D
Thanks for any ideas. PaJa
Message #2 by Levent Camlibel <lcamlib@C...> on Wed, 14 Feb 2001 09:07:48 -0500
|
|
Hello Pavel,
you might use syntax similar to this
SQLParameter parameterContactTitle = new SQLParameter("@ContactTitle",SQLDataType.NVarChar, 50);
parameterContactTitle.IsNullable=true;
parameterContactTitle.Value=ContactTitle;
myCommand.Parameters.Add(parameterContactTitle);
Tuesday, February 13, 2001, 9:21:57 PM, you wrote:
PH> I have this code for insert a new member into database. All work fine,
PH> but field BirthDate isn't requsted. If users don't fill birthDate how to
PH> I may insert NULL value? Help me someone?
PH> My code is there:
PH> ========================================================================
PH> =========================================
PH> SQLConnection Conn = new SQLConnection(SQL_CONNECTION_STRING);
PH> SQLCommand myCommand = new SQLCommand("exec sp_AddMember
PH> @UserName, @UserPassword, @Attributes, " +
PH> " @Email, @FirstName,
PH> @LastName, " +
PH> " @BirthDate, @icqNumber",
PH> Conn);
PH> myCommand.Parameters.Add(new SQLParameter("@UserName",
PH> SQLDataType.VarChar, 15));
PH> myCommand.Parameters["@UserName"].Value = UserName;
PH> myCommand.Parameters.Add(new SQLParameter("@UserPassword",
PH> SQLDataType.VarChar, 10));
PH> myCommand.Parameters["@UserPassword"].Value = UserPassword;
PH> myCommand.Parameters.Add(new SQLParameter("@Attributes",
PH> SQLDataType.Int));
PH> myCommand.Parameters["@Attributes"].Value = Attributes;
PH> myCommand.Parameters.Add(new SQLParameter("@Email",
PH> SQLDataType.VarChar, 150));
PH> myCommand.Parameters["@Email"].Value = Email;
PH> myCommand.Parameters.Add(new SQLParameter("@FirstName",
PH> SQLDataType.VarChar, 50));
PH> myCommand.Parameters["@FirstName"].Value = FirstName;
PH> myCommand.Parameters.Add(new SQLParameter("@LastName",
PH> SQLDataType.VarChar, 50));
PH> myCommand.Parameters["@LastName"].Value = LastName;
PH> if (BirthDate != DateTime.Empty) {
PH> myCommand.Parameters.Add(new SQLParameter("@BirthDate",
PH> SQLDataType.DateTime));
PH> myCommand.Parameters["@BirthDate"].Value = BirthDate;
PH> } else {
PH> myCommand.Parameters.Add(new SQLParameter("@BirthDate",
PH> SQLDataType.DateTime));
PH> myCommand.Parameters["@BirthDate"].Value = DateTime.Empty;
PH> }
PH> myCommand.Parameters.Add(new SQLParameter("@icqNumber",
PH> SQLDataType.VarChar, 50));
PH> myCommand.Parameters["@icqNumber"].Value = icqNumber;
PH> myCommand.ActiveConnection.Open();
PH> myCommand.ExecuteNonQuery();
PH> ========================================================================
PH> ====
PH> Thanks for any ideas. PaJa
--
Best regards,
Levent mailto:lcamlib@c...
|
|
 |