My Code:
try
{
for (int i = 0; i < gradePolicyGridView.Rows.Count - 1; i++)
{
db.command.Parameters.Add("@ClassInterval", SqlDbType.VarChar).Value = gradePolicyGridView.Rows[i].Cells[1].Value.ToString();
db.command.Parameters.Add("@LetterGrade", SqlDbType.VarChar).Value = gradePolicyGridView.Rows[i].Cells[2].Value.ToString();
db.command.Parameters.Add("@GradePoint", SqlDbType.Decimal).Value = Convert.ToDecimal(gradePolicyGridView.Rows[i].Cells[3].Value.ToString());
db.Adapter("insertGradePolicy", true);
MessageBox.Show("Data saved successfully...");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
In my GridView controls I am putting 3 rows but, when I press the save button the GridView clean its all values and inserting only 1 -row in my sql server table. How, can I insert multiple rows from my GriedView.
My Stored procedure :
USE [SMS2]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[insertGradePolicy]
(
@ClassInterval [varchar](50),
@LetterGrade [varchar](50),
@GradePoint [decimal])
AS INSERT INTO [SMS2].[dbo].[GradePolicy]
(
[ClassInterval],
[LetterGrade],
[GradePoint])
VALUES
(
@ClassInterval,
@LetterGrade,
@GradePoint
)
My Table:
USE [SMS2]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[GradePolicy](
[SL] [int] IDENTITY(1,1) NOT NULL,
[ClassInterval] [varchar](50) NULL,
[LetterGrade] [varchar](50) NULL,
[GradePoint] [decimal](18, 0) NULL,
CONSTRAINT [PK_GradePolicy] PRIMARY KEY CLUSTERED
(
[SL] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
Please tell me where is the problem in my code or how can I update my c# code to insert multiple rows without cleaning GridView fields.
Thank you..