andy.vladimirsky
New member
- Local time
- Today, 02:30
- Joined
- Apr 21, 2012
- Messages
- 3
dear friends !
could you please help me in resolving my issue (if any) !
i have a tiny sql server database.
it contains one table (nothing special - just first name, last name, phone, mail. [phone] and [mail] are optional):
CREATE TABLE [dbo].[tbl_contact](
[id] [int] IDENTITY (1,1) NOT NULL,
[name_last] [nvarchar] (32) NOT NULL,
[name_first] [nvarchar] (32) NOT NULL,
[phone] [nvarchar] (32) NULL,
[mail] [nvarchar] (32) NULL,
CONSTRAINT [PK_tbl_contact] PRIMARY KEY CLUSTERED ( [id] ASC ) ON [PRIMARY]
the database contains one stored procedure (nothing special - just insert a single record in the table. @phone and @mail are optional):
ALTER PROCEDURE [dbo].[prc_add_contact]
@name_last nvarchar ( 32 ),
@name_first nvarchar ( 32 ),
@phone nvarchar ( 32 ) = null,
@mail nvarchar ( 32 ) = null
AS
BEGIN
SET NOCOUNT ON;
insert [tbl_contact] ( [name_last], [name_first], [phone], [mail] )
values ( @name_last, @name_first, @phone, @mail )
end
i have a tiny ms access project file and a visual basic code within it.
this piece of code works fine (the way i expected) :
CurrentProject.Connection.Execute "[prc_add_contact] @name_last = 'smith', @name_first = 'robert', @mail = 'robert.smith ...' ;"
this one works fine (from technical point of view) but insert value for mail address into [phone] field of the table:
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = "[prc_add_contact]"
cmd.CommandType = adCmdStoredProc
Set prm_namelast = cmd.CreateParameter("@name_last", adVarWChar, adParamInput, Len("smith"), "smith")
Set prm_namefirst = cmd.CreateParameter("@name_first", adVarWChar, adParamInput, Len("robert"), "robert")
Set prm_mail = cmd.CreateParameter("@mail", adVarWChar, adParamInput, Len("robert.smith ..."), "robert.smith ...")
cmd.Parameters.Append prm_namelast
cmd.Parameters.Append prm_namefirst
cmd.Parameters.Append prm_mail
cmd.Execute
Set cmd = Nothing
so my first question is how to pass the first, the second and the fourth parameters and nothing else. (i do really believe '= NULL' means i may not to pass it at all when calling stored procedure.)
(please help me - i almost broke my brain.)
thank you in advance !
av
could you please help me in resolving my issue (if any) !
i have a tiny sql server database.
it contains one table (nothing special - just first name, last name, phone, mail. [phone] and [mail] are optional):
CREATE TABLE [dbo].[tbl_contact](
[id] [int] IDENTITY (1,1) NOT NULL,
[name_last] [nvarchar] (32) NOT NULL,
[name_first] [nvarchar] (32) NOT NULL,
[phone] [nvarchar] (32) NULL,
[mail] [nvarchar] (32) NULL,
CONSTRAINT [PK_tbl_contact] PRIMARY KEY CLUSTERED ( [id] ASC ) ON [PRIMARY]
the database contains one stored procedure (nothing special - just insert a single record in the table. @phone and @mail are optional):
ALTER PROCEDURE [dbo].[prc_add_contact]
@name_last nvarchar ( 32 ),
@name_first nvarchar ( 32 ),
@phone nvarchar ( 32 ) = null,
@mail nvarchar ( 32 ) = null
AS
BEGIN
SET NOCOUNT ON;
insert [tbl_contact] ( [name_last], [name_first], [phone], [mail] )
values ( @name_last, @name_first, @phone, @mail )
end
i have a tiny ms access project file and a visual basic code within it.
this piece of code works fine (the way i expected) :
CurrentProject.Connection.Execute "[prc_add_contact] @name_last = 'smith', @name_first = 'robert', @mail = 'robert.smith ...' ;"
this one works fine (from technical point of view) but insert value for mail address into [phone] field of the table:
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = "[prc_add_contact]"
cmd.CommandType = adCmdStoredProc
Set prm_namelast = cmd.CreateParameter("@name_last", adVarWChar, adParamInput, Len("smith"), "smith")
Set prm_namefirst = cmd.CreateParameter("@name_first", adVarWChar, adParamInput, Len("robert"), "robert")
Set prm_mail = cmd.CreateParameter("@mail", adVarWChar, adParamInput, Len("robert.smith ..."), "robert.smith ...")
cmd.Parameters.Append prm_namelast
cmd.Parameters.Append prm_namefirst
cmd.Parameters.Append prm_mail
cmd.Execute
Set cmd = Nothing
so my first question is how to pass the first, the second and the fourth parameters and nothing else. (i do really believe '= NULL' means i may not to pass it at all when calling stored procedure.)
(please help me - i almost broke my brain.)
thank you in advance !
av