javierpdx
asked on
Update sql Statement based on a GridView field
Hello,
I am trying run an update statement based on a current GridView. The reason is that if the sql table data is updated while in the current GridView, I only want to set an update for each record of the currently selected data.
Insert Statement:
asp:BoundField DataField="StudentID"
Is is possible to do this, or is there a better way to achieve this?
Thank you for any assistance.
I am trying run an update statement based on a current GridView. The reason is that if the sql table data is updated while in the current GridView, I only want to set an update for each record of the currently selected data.
Insert Statement:
using (SqlCommand command = new SqlCommand())
{command.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
command.CommandText = @"insert into [Comm](CommType, StudentID)
values(@CommType, @StudentID)";
command.Parameters.Add("@CommType", SqlDbType.VarChar, 16).Value = "Emailed";
command.Parameters.Add("@StudentID", SqlDbType.VarChar, 9).Value = **How do I add a GridView Column Name here for each record in my GridView?***;
command.Connection.Open();
command.ExecuteNonQuery();
command.Parameters.Clear();
command.Connection.Close();
Comm Table: [ID] [int] IDENTITY(1,1) NOT NULL,
[CommType] [varchar](16) NULL,
[StudentID] [varchar](9) NULL,
The field I want to grab from the GridView is:asp:BoundField DataField="StudentID"
Is is possible to do this, or is there a better way to achieve this?
Thank you for any assistance.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the expert advise. I appreciate it.
This ended up working:
command.CommandText = @"insert into [Communication](CommType, ID)
values(@CommType, @ID)"
command.Parameters.Add("@C ommType", SqlDbType.VarChar, 16).Value = Row.Cells[12].Text;
command.Parameters.Add("@I D", SqlDbType.VarChar, 9).Value = "0" + Row.Cells[2].Text;
This ended up working:
command.CommandText = @"insert into [Communication](CommType, ID)
values(@CommType, @ID)"
command.Parameters.Add("@C
command.Parameters.Add("@I
ASKER