Попытка вставить переменные данные через веб-страницу в таблицы SQL с помощью C # - PullRequest
0 голосов
/ 16 августа 2011

Я пытаюсь вставить данные в таблицу SQL с помощью хранимой процедуры. Я использую несколько переменных для этой вставки через заливку из C #.

Когда я нажимаю на кнопку, данные не передаются в таблицу. Я верю, что это как-то связано с постом обратно, но я не уверен, кто это реализует.

Вот код SQL.

USE [Dispatch]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE

[dbo].[spMissedJobsTableInsert]

--DATES--
@SUN SMALLDATETIME,
@MON SMALLDATETIME,
@TUE SMALLDATETIME,
@WED SMALLDATETIME,
@THU SMALLDATETIME,
@FRI SMALLDATETIME,
@SAT SMALLDATETIME,
--SUPERVISOR--
@SUPERVISOR VARCHAR(50),
--DISPATCHRS--
@DISPATCHER1 VARCHAR(50),
@DISPATCHER2 VARCHAR(50),
@DISPATCHER3 VARCHAR(50),
@DISPATCHER4 VARCHAR(50),
@DISPATCHER5 VARCHAR(50),
@DISPATCHER6 VARCHAR(50),
@DISPATCHER7 VARCHAR(50),
@DISPATCHER8 VARCHAR(50),
@DISPATCHER9 VARCHAR(50),
@DISPATCHER10 VARCHAR(50),
@DISPATCHER11 VARCHAR(50),
@DISPATCHER12 VARCHAR(50),
@DISPATCHER13 VARCHAR(50),
@DISPATCHER14 VARCHAR(50),
--1ST DISPATCHER AREAS--
@AREA1_1 VARCHAR(20),
@AREA1_2 VARCHAR(20),
@AREA1_3 VARCHAR(20),
@AREA1_4 VARCHAR(20),
@AREA1_5 VARCHAR(20),
@AREA1_6 VARCHAR(20),
@AREA1_7 VARCHAR(20),
--1ST DISPATCHER MISSED--
@MISSED1_1 INT,
@MISSED1_2 INT,
@MISSED1_3 INT,
@MISSED1_4 INT,
@MISSED1_5 INT,
@MISSED1_6 INT,
@MISSED1_7 INT,
--2ND DISPATCHER AREAS--
@AREA2_1 VARCHAR(20),
@AREA2_2 VARCHAR(20),
@AREA2_3 VARCHAR(20), 
@AREA2_4 VARCHAR(20),
@AREA2_5 VARCHAR(20),
@AREA2_6 VARCHAR(20),
@AREA2_7 VARCHAR(20),
--2ND DISPATCHER MISSED--
@MISSED2_1 INT,
@MISSED2_2 INT,
@MISSED2_3 INT,
@MISSED2_4 INT,
@MISSED2_5 INT,
@MISSED2_6 INT,
@MISSED2_7 INT

AS BEGIN

--1ST DISPATCHER--
IF @MISSED1_1 >0 AND @AREA1_1 <> ''
BEGIN 
INSERT INTO 
Dispatch.dbo.tblMissedJobs  ([DATE], SUPERVISOR, AREA, DISPATCHER, MISSED)
VALUES (@SUN, @SUPERVISOR, @AREA1_1, @DISPATCHER1, @MISSED1_1)
END

IF @MISSED1_2 >0 AND @AREA1_2 <> ''
BEGIN 
INSERT INTO 
Dispatch.dbo.tblMissedJobs  ([DATE], SUPERVISOR, AREA, DISPATCHER, MISSED)
VALUES (@MON, @SUPERVISOR, @AREA1_2, @DISPATCHER1, @MISSED1_2)
END

IF @MISSED1_3 >0 AND @AREA1_3 <> ''
BEGIN 
INSERT INTO 
Dispatch.dbo.tblMissedJobs  ([DATE], SUPERVISOR, AREA, DISPATCHER, MISSED)
VALUES (@TUE, @SUPERVISOR, @AREA1_3, @DISPATCHER1, @MISSED1_3)
END

IF @MISSED1_4 >0 AND @AREA1_4 <> ''
BEGIN 
INSERT INTO 
Dispatch.dbo.tblMissedJobs  ([DATE], SUPERVISOR, AREA, DISPATCHER, MISSED)
VALUES (@WED, @SUPERVISOR, @AREA1_4, @DISPATCHER1, @MISSED1_4)
END

IF @MISSED1_5 >0 AND @AREA1_5 <> ''
BEGIN 
INSERT INTO 
Dispatch.dbo.tblMissedJobs  ([DATE], SUPERVISOR, AREA, DISPATCHER, MISSED)
VALUES (@THU, @SUPERVISOR, @AREA1_5, @DISPATCHER1, @MISSED1_5)
END

IF @MISSED1_6 >0 AND @AREA1_6 <> ''
BEGIN 
INSERT INTO 
Dispatch.dbo.tblMissedJobs  ([DATE], SUPERVISOR, AREA, DISPATCHER, MISSED)
VALUES (@FRI, @SUPERVISOR, @AREA1_6, @DISPATCHER1, @MISSED1_6)
END

IF @MISSED1_7 >0 AND @AREA1_7 <> ''
BEGIN 
INSERT INTO 
Dispatch.dbo.tblMissedJobs  ([DATE], SUPERVISOR, AREA, DISPATCHER, MISSED)
VALUES (@SAT, @SUPERVISOR, @AREA1_7, @DISPATCHER1, @MISSED1_7)
END

END

вот код aspx c #

  public void clear_form()
    {
        DropDownList2.SelectedValue = " "; DropDownList3.SelectedValue = " "; DropDownList4.SelectedValue = " "; DropDownList5.SelectedValue = " "; DropDownList6.SelectedValue = " ";
        DropDownList7.SelectedValue = " "; DropDownList8.SelectedValue = " "; DropDownList9.SelectedValue = " "; DropDownList10.SelectedValue = " "; DropDownList11.SelectedValue = " ";
        DropDownList12.SelectedValue = " "; DropDownList13.SelectedValue = " "; DropDownList14.SelectedValue = " "; DropDownList15.SelectedValue = " "; 
    }

    public void insert_record(string sunday, string monday, string tuesday, string wednesday, string thursday, string friday, string saturday,
                              string supervisor,
                              string d1, string d2, string d3, string d4, string d5, string d6, string d7, string d8, string d9, string d10, string d11, string d12, string d13, string d14,
                              string a1_1, string a1_2, string a1_3, string a1_4, string a1_5, string a1_6, string a1_7,
                              string m1_1, string m1_2, string m1_3, string m1_4, string m1_5, string m1_6, string m1_7)
    {
        SqlConnection sqlconn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["DispatchConnectionString"].ConnectionString);
        SqlCommand insertcmd1 = new
        SqlCommand("spMissedJobsTableInsert", sqlconn1);
        insertcmd1.CommandType = CommandType.StoredProcedure;
        insertcmd1.CommandTimeout = 30;
        insertcmd1.Parameters.Add(new SqlParameter("@SUN", sunday));
        insertcmd1.Parameters.Add(new SqlParameter("@MON", monday));
        insertcmd1.Parameters.Add(new SqlParameter("@TUE", tuesday));
        insertcmd1.Parameters.Add(new SqlParameter("@WED", wednesday));
        insertcmd1.Parameters.Add(new SqlParameter("@THU", thursday));
        insertcmd1.Parameters.Add(new SqlParameter("@FRI", friday));
        insertcmd1.Parameters.Add(new SqlParameter("@SAT", saturday));

        insertcmd1.Parameters.Add(new SqlParameter("@SUPERVISOR", supervisor));

        insertcmd1.Parameters.Add(new SqlParameter("@DISPATCHER1", d1));
        insertcmd1.Parameters.Add(new SqlParameter("@DISPATCHER2", d2));
        insertcmd1.Parameters.Add(new SqlParameter("@DISPATCHER3", d3));
        insertcmd1.Parameters.Add(new SqlParameter("@DISPATCHER4", d4));
        insertcmd1.Parameters.Add(new SqlParameter("@DISPATCHER5", d5));
        insertcmd1.Parameters.Add(new SqlParameter("@DISPATCHER6", d6));
        insertcmd1.Parameters.Add(new SqlParameter("@DISPATCHER7", d7));
        insertcmd1.Parameters.Add(new SqlParameter("@DISPATCHER8", d8));
        insertcmd1.Parameters.Add(new SqlParameter("@DISPATCHER9", d9));
        insertcmd1.Parameters.Add(new SqlParameter("@DISPATCHER10", d10));
        insertcmd1.Parameters.Add(new SqlParameter("@DISPATCHER11", d11));
        insertcmd1.Parameters.Add(new SqlParameter("@DISPATCHER12", d12));
        insertcmd1.Parameters.Add(new SqlParameter("@DISPATCHER13", d13));
        insertcmd1.Parameters.Add(new SqlParameter("@DISPATCHER14", d14));

        insertcmd1.Parameters.Add(new SqlParameter("@AREA1_1", a1_1));
        insertcmd1.Parameters.Add(new SqlParameter("@AREA1_2", a1_2));
        insertcmd1.Parameters.Add(new SqlParameter("@AREA1_3", a1_3));
        insertcmd1.Parameters.Add(new SqlParameter("@AREA1_4", a1_4));
        insertcmd1.Parameters.Add(new SqlParameter("@AREA1_5", a1_5));
        insertcmd1.Parameters.Add(new SqlParameter("@AREA1_6", a1_6));
        insertcmd1.Parameters.Add(new SqlParameter("@AREA1_7", a1_7));

        insertcmd1.Parameters.Add(new SqlParameter("@MISSED1_1", m1_1));
        insertcmd1.Parameters.Add(new SqlParameter("@MISSED1_2", m1_2));
        insertcmd1.Parameters.Add(new SqlParameter("@MISSED1_3", m1_3));
        insertcmd1.Parameters.Add(new SqlParameter("@MISSED1_4", m1_4));
        insertcmd1.Parameters.Add(new SqlParameter("@MISSED1_5", m1_5));
        insertcmd1.Parameters.Add(new SqlParameter("@MISSED1_6", m1_6));
        insertcmd1.Parameters.Add(new SqlParameter("@MISSED1_7", m1_7));

        try
        {
            sqlconn1.Open();
            insertcmd1.ExecuteNonQuery();
        }
        catch (Exception insert_ex1)
        {
            Label20.Text = insert_ex1.Message;
        }
        finally
        {
            sqlconn1.Close();
            sqlconn1.Dispose();
        }

    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        insert_record(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text, TextBox7.Text,
                      DropDownList1.SelectedValue,
                      Label1.Text, Label2.Text, Label3.Text, Label4.Text, Label5.Text, Label6.Text, Label7.Text, Label8.Text, Label9.Text, Label10.Text,
                      Label11.Text, Label12.Text, Label13.Text, Label14.Text,
                      DropDownList2.SelectedValue, DropDownList4.SelectedValue, DropDownList6.SelectedValue, DropDownList8.SelectedValue, DropDownList10.SelectedValue,
                      DropDownList12.SelectedValue, DropDownList14.SelectedValue,
                      DropDownList3.SelectedValue, DropDownList5.SelectedValue, DropDownList7.SelectedValue, DropDownList9.SelectedValue, DropDownList11.SelectedValue,
                      DropDownList13.SelectedValue, DropDownList15.SelectedValue);
        clear_form();
        Label16.Visible = true;
        Label16.Text = "Missed Jobs Updated";
    }
...