title: The request failed for '' (procedure)" because it is a table object - error
body: <p>I have three tables: </p>
  
  <ul>
  <li>dbo.Student</li>
  <li>dbo.Request</li>
  <li>dbo.RequestLine (which is the associated table between the former two, contains a composite primary key STUD_ID and REQ_ID, and an attribute REQ_DATE)</li>
  </ul>
  
  <p>I am trying to insert records into the <code>dbo.RequestLine</code> table. However, I am getting an error saying:</p>
  
  <blockquote>
    <p>System.Data.SqlClient.SqlException: The request for procedure 'RequestLine' failed because 'RequestLine' is a table object.</p>
  </blockquote>
  
  <p>Here are the DDL statements for the three tables:</p>
  
  <pre><code>CREATE TABLE [dbo].[Request]
  (
      [REQ_ID] [int] IDENTITY(10000005,1) NOT NULL,
      [REQ_STAT] [varchar](12) NULL,
      [REQ_CAT] [varchar](15) NULL,
      [ADMIN_ID] [smallint] NULL,
      [COOR_ID] [smallint] NULL,
  
      CONSTRAINT [PK_Request] 
          PRIMARY KEY CLUSTERED ([REQ_ID] ASC)
  )
  
  ALTER TABLE [dbo].[Request] WITH CHECK 
      ADD CONSTRAINT [FK_Request_Admin] 
          FOREIGN KEY([ADMIN_ID]) REFERENCES [dbo].[Admin] ([ADMIN_ID])
  GO
  
  ALTER TABLE [dbo].[Request] CHECK CONSTRAINT [FK_Request_Admin]
  GO
  
  ALTER TABLE [dbo].[Request]  WITH CHECK 
      ADD CONSTRAINT [FK_Request_Coordinator] 
          FOREIGN KEY([COOR_ID]) REFERENCES [dbo].[Coordinator] ([COOR_ID])
  GO
  
  ALTER TABLE [dbo].[Request] CHECK CONSTRAINT [FK_Request_Coordinator]
  GO
  
  CREATE TABLE [dbo].[Student]
  (
      [STUD_ID] [int] IDENTITY(1000009,1) NOT NULL,
      [STUD_NAM] [varchar](30) NOT NULL,
      [STUD_EMAIL] [varchar](50) NULL,
      [CAMP_NAM] [varchar](50) NULL,
      [CAMP_ZIP] [int] NULL,
      [STUD_TYP] [char](5) NOT NULL,
  
      CONSTRAINT [PK_Student] 
          PRIMARY KEY CLUSTERED ([STUD_ID] ASC)
  ) 
  GO
  
  ALTER TABLE [dbo].[Student] WITH CHECK 
      ADD CONSTRAINT [FK_Student_Campus] 
          FOREIGN KEY([CAMP_NAM], [CAMP_ZIP]) REFERENCES [dbo].[Campus] ([CAMP_NAM], [CAMP_ZIP])
  GO
  
  ALTER TABLE [dbo].[Student] CHECK CONSTRAINT [FK_Student_Campus]
  GO
  
  CREATE TABLE [dbo].[RequestLine]
  (
      [STUD_ID] [int] NOT NULL,
      [REQ_ID] [int] NOT NULL,
      [REQ_DATE] [date] NOT NULL,
  
      CONSTRAINT [PK_RequestLine] 
          PRIMARY KEY CLUSTERED ([STUD_ID] ASC, [REQ_ID] ASC)
  )
  GO
  
  ALTER TABLE [dbo].[RequestLine]  WITH CHECK 
      ADD CONSTRAINT [FK_RequestLine_Request] 
          FOREIGN KEY([REQ_ID]) REFERENCES [dbo].[Request] ([REQ_ID])
  GO
  
  ALTER TABLE [dbo].[RequestLine] CHECK CONSTRAINT [FK_RequestLine_Request]
  GO
  
  ALTER TABLE [dbo].[RequestLine]  WITH CHECK 
      ADD CONSTRAINT [FK_RequestLine_Student] 
          FOREIGN KEY([STUD_ID]) REFERENCES [dbo].[Student] ([STUD_ID])
  GO
  
  ALTER TABLE [dbo].[RequestLine] CHECK CONSTRAINT [FK_RequestLine_Student]
  GO
  </code></pre>
  
  <p>Here are the three stored procedures I have:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[Req_InsertNew]
      (@REQ_STAT varchar(12),
       @REQ_CAT varchar(15),
       @ADMIN_ID smallint,
       @COOR_ID smallint)
  AS
  BEGIN
      SET NOCOUNT ON
  
      INSERT INTO dbo.Request (REQ_STAT, REQ_CAT, ADMIN_ID, COOR_ID)
      VALUES (@REQ_STAT, @REQ_CAT, @ADMIN_ID, @COOR_ID);
  
      DECLARE @REQ_ID INT
      SET @REQ_ID = SCOPE_IDENTITY()
      SELECT @REQ_ID
  END
  
  ALTER PROCEDURE [dbo].[Stud_InsertNew2]
      (@STUD_NAM varchar(30),
       @STUD_EMAIL varchar(50),
       @CAMP_NAM varchar(50),
       @CAMP_ZIP int,
       @STUD_TYP char(5))
  AS
  BEGIN
      DECLARE @temptable TABLE (newSTUDID int, STUDTYPE char);
  
      SET NOCOUNT ON
  
      INSERT INTO dbo.Student(STUD_NAM, STUD_EMAIL, CAMP_NAM, CAMP_ZIP, STUD_TYP)
      VALUES (@STUD_NAM, @STUD_EMAIL, @CAMP_NAM, @CAMP_ZIP, @STUD_TYP);
  
      DECLARE @STUD_ID INT
      SET @STUD_ID = SCOPE_IDENTITY()
      SELECT @STUD_ID
  END
  
  ALTER PROCEDURE [dbo].[ReqLine_Insert]
      (@STUD_ID int,
       @REQ_ID int,
       @REQ_DATE date)
  AS
  BEGIN
      INSERT INTO dbo.RequestLine (STUD_ID, REQ_ID, REQ_DATE)
      VALUES (@STUD_ID, @REQ_ID, @REQ_DATE)
  END
  </code></pre>
  
  <p>And I am trying to use <code>ExecuteScalar()</code> to retrieve the <code>REQ_ID</code> and <code>STUD_ID</code> and put them into the <code>RequestLine</code> table. </p>
  
  <p>Here is the C# code:</p>
  
  <pre><code>int campzip = int.Parse(ddlCamp.SelectedValue.Trim());
  int adminid = int.Parse(ddlAdmin.SelectedValue.Trim());
  int coorid = int.Parse(txtCoorID.Text.Trim());
  
  DateTime ReqDate = DateTime.ParseExact(txtReqDate.Text, "yyyy-MM-dd", null);
  
  using (var connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("cis-laredoConnectionString")))
  {
      connection.Open();
  
      var cmd = new SqlCommand("dbo.Stud_InsertNew2", connection);
      cmd.CommandType = CommandType.StoredProcedure;
  
      cmd.Parameters.AddWithValue("@STUD_NAM", txtStdName.Text);
      cmd.Parameters.AddWithValue("@STUD_EMAIL", txtStdEmail.Text);
      cmd.Parameters.AddWithValue("@CAMP_NAM", ddlCamp.SelectedItem.ToString());
      cmd.Parameters.AddWithValue("@CAMP_ZIP", campzip);
      cmd.Parameters.AddWithValue("@STUD_TYP", "Other");
  
      int STUD_ID = (int)cmd.ExecuteScalar();
      cmd.Dispose();
  
      connection.Close();
  
      connection.Open();
  
      var cmd1 = new SqlCommand("dbo.Req_InsertNew", connection);
      cmd1.CommandType = CommandType.StoredProcedure;
  
      cmd1.Parameters.AddWithValue("@REQ_STAT", "Submitted");
      cmd1.Parameters.AddWithValue("@REQ_CAT", "Uniform");
      cmd1.Parameters.AddWithValue("@ADMIN_ID", adminid);
      cmd1.Parameters.AddWithValue("@COOR_ID", coorid);;
  
      int REQ_ID = (int)cmd1.ExecuteScalar();
  
      cmd1.Dispose();
      connection.Close();
  
      // post back info. to dbo.RequestLine table in sql server
      connection.Open();
  
      var cmd2 = new SqlCommand("dbo.ReqLine_Insert", connection);
      cmd2.CommandType = CommandType.StoredProcedure;
  
      cmd2.Parameters.AddWithValue("@STUD_ID", STUD_ID);
      cmd2.Parameters.AddWithValue("@REQ_ID", REQ_ID);
      cmd2.Parameters.Add("@REQ_DATE", SqlDbType.Date).Value = ReqDate;
  
      cmd2.ExecuteNonQuery();
      cmd2.Dispose();
  
      connection.Close();
  }
  </code></pre>
  
  <p>Any help would be appreciated!</p>