I tried to get be independant but, please oh please will someone help me out! I just can't seem to get a grip on the way to approach this and there is way too much chaotic info on the web...
I need:
1. entry form submit -- 2 fields from form inserted into table 1
2. remaining form fields and primary key of above insert ->inserted into table 2 & 3
I have been able to insert the record but to do it "correctly" I am thinking that I need to use stored procedures and such as opposed to manually running query after query...
Please can someone look at the code below
(and this if you want to see my working insert -> and help me...
==> fix the problem with the below call to stored procedure
==> let me know what i do next in the DB (?add another stored procedure? add more into the initial?)
==> let me know what i do next in the aspx.cs page (?add another query/call to stored procedure before the "conn.Close();"? add that after the close() and re-do all code to open the connection??)
//****C# code *******//
string ltlUserId;
SqlConnection conn = new SqlConnection("server=xxx;database=xxx;uid=xxx;pwd=xxx
SqlCommand cmd = new SqlCommand("AddProgramAdmin", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param1 = new SqlParameter("@username", SqlDbType.VarChar);
param1.Value = (Request.Form["cpm_email"]);
SqlParameter param2 = new SqlParameter("@admin_level", SqlDbType.VarChar);
param2.Value = "ARC Program Admin";
SqlParameter param3 = new SqlParameter("RETURN_VALUE", SqlDbType.Int);
param3.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(param1);
cmd.Parameters.Add(param2);
cmd.Parameters.Add(param3);
conn.Open();
cmd.ExecuteNonQuery();
//Console.writeLine ( cmd.Parameters["RETURN_VALUE"].Value.ToString());
conn.Close();
//****Stored Procedure *******//
CREATE Procedure dbo.AddProgramAdmin
(
@username varchar(100),
@admin_level varchar(100)
)
AS
declare @user_id int
insert into acr_admin (username,admin_level) values(@username,@admin_level)
select @user_id=@@IDENTITY from acr_admin
return @user_id
GO
//****Error *******//
Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'acr_admin'.
--yes there is a table acr_admin
--I have also tried above with scope_identity...
I need:
1. entry form submit -- 2 fields from form inserted into table 1
2. remaining form fields and primary key of above insert ->inserted into table 2 & 3
I have been able to insert the record but to do it "correctly" I am thinking that I need to use stored procedures and such as opposed to manually running query after query...
Please can someone look at the code below
(and this if you want to see my working insert -> and help me...
==> fix the problem with the below call to stored procedure
==> let me know what i do next in the DB (?add another stored procedure? add more into the initial?)
==> let me know what i do next in the aspx.cs page (?add another query/call to stored procedure before the "conn.Close();"? add that after the close() and re-do all code to open the connection??)
//****C# code *******//
string ltlUserId;
SqlConnection conn = new SqlConnection("server=xxx;database=xxx;uid=xxx;pwd=xxx
SqlCommand cmd = new SqlCommand("AddProgramAdmin", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param1 = new SqlParameter("@username", SqlDbType.VarChar);
param1.Value = (Request.Form["cpm_email"]);
SqlParameter param2 = new SqlParameter("@admin_level", SqlDbType.VarChar);
param2.Value = "ARC Program Admin";
SqlParameter param3 = new SqlParameter("RETURN_VALUE", SqlDbType.Int);
param3.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(param1);
cmd.Parameters.Add(param2);
cmd.Parameters.Add(param3);
conn.Open();
cmd.ExecuteNonQuery();
//Console.writeLine ( cmd.Parameters["RETURN_VALUE"].Value.ToString());
conn.Close();
//****Stored Procedure *******//
CREATE Procedure dbo.AddProgramAdmin
(
@username varchar(100),
@admin_level varchar(100)
)
AS
declare @user_id int
insert into acr_admin (username,admin_level) values(@username,@admin_level)
select @user_id=@@IDENTITY from acr_admin
return @user_id
GO
//****Error *******//
Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'acr_admin'.
--yes there is a table acr_admin
--I have also tried above with scope_identity...