ASP.NET中SQL Server中的多个项目的相同ID

时间:2017-08-31 11:23:19

标签: sql sql-server vb.net

请帮助我,因为我想将相同的ID插入到结算应用程序的多个记录中。

表格结构如下:

CREATE TABLE [dbo].[Service_Billing] 
(
    [Service_ID]  INT            IDENTITY (1, 1) NOT NULL,
    [BillID]      INT            NULL,
    [BillDate]    DATETIME       NOT NULL,
    [Contrid]     NCHAR (10)     NULL,
    [Description] NVARCHAR (250) NULL,
    [Qty]         NCHAR (10)     NULL,
    [Post]        NVARCHAR (50)  NULL,
    [Period]      NCHAR (10)     NULL,
    [Rate]        NCHAR (10)     NULL,
    [Amount]      NCHAR (10)     NULL,

    PRIMARY KEY CLUSTERED ([Service_ID] ASC)
);

存储过程如下所示:

CREATE PROCEDURE [dbo].[BillAdd]
    @BillDate    DATETIME,
    @Contrid     NCHAR(10),
    @Description NVARCHAR(250),
    @Qty         NCHAR(10),
    @Post        NVARCHAR(50),
    @Period      NCHAR(10),
    @Rate        NCHAR(10),
    @Amount      NCHAR(10)
AS
    DECLARE @ser INT = 0
    SET @ser = (SELECT MAX(BillID) FROM Service_Billing) + 1

    INSERT INTO Service_Billing(BillID, BillDate, ContrID, Qty, Post, Description, Period, Rate, Amount) 
    VALUES(@ser, @BillDate, @ContrID, @Qty, @Post, @Description, @Period, @Rate, @Amount)

插入命令如下:

Using con As New SqlConnection(strConnString)
    For i As Integer = 0 To Gridview1.Rows.Count - 1
        Dim Qty As DropDownList = DirectCast(Gridview1.Rows(i).FindControl("Qty"), DropDownList)
        Dim Post As DropDownList = DirectCast(Gridview1.Rows(i).FindControl("Post"), DropDownList)
        Dim Period As TextBox = DirectCast(Gridview1.Rows(i).FindControl("Period"), TextBox)
        Dim Rate As TextBox = DirectCast(Gridview1.Rows(i).FindControl("Rate"), TextBox)
        Dim Amountttl As TextBox = DirectCast(Gridview1.Rows(i).FindControl("Amount"), TextBox)

        Using cmd As New SqlCommand
            cmd.Connection = con
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "BillAdd"

            cmd.Parameters.AddWithValue("@BillDate", Date.ParseExact(billedate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture))
            cmd.Parameters.AddWithValue("@ContrID", aggrmnt.SelectedValue)
            cmd.Parameters.AddWithValue("@Qty", Qty.SelectedValue)
            cmd.Parameters.AddWithValue("@Post", Post.SelectedItem.Text)
            cmd.Parameters.AddWithValue("@Description", NewBill_Description.Text)
            cmd.Parameters.AddWithValue("@Period", Period.Text)
            cmd.Parameters.AddWithValue("@Rate", Rate.Text)
            cmd.Parameters.AddWithValue("@Amount", Amountttl.Text)

            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()
        End Using

        Next
        'MsgBox("Bill Processed Sucessfully", vbOKOnly)
    End Using

,输出如下图所示:

enter image description here

我希望使用下面的代码ID {手动更新}

enter image description here

0 个答案:

没有答案