Click here to Skip to main content
15,071,899 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Frnds,
How i insert Datagridview and Textbox values save at a time using button..



With Regards,
Vivek .R
Posted
Comments
Ramug10 24-Feb-14 2:07am
   
could you provide me more details on your requirement.
Member 10611310 24-Feb-14 2:27am
   
for (int i = 0; i < dgvScreenDetails.Rows.Count; i++)
{

cmd.CommandText = "insert into UserHdr(UserType,UserId,UserName,DepartmentId,DepartmentName,Password,ScreenCode,ScreenName,DeleteFlag) values(@UserType,@UserId,@UserName,@DepartmentId,@DepartmentName,@Password,@ScreenCode,@ScreenName,'N')";

if (rbAdmin.Checked == true)
{
cmd.Parameters.Add("@UserType", SqlDbType.NVarChar).Value = rbAdmin.Text;
}
else if (rbManagement.Checked == true)
{
cmd.Parameters.Add("@UserType", SqlDbType.NVarChar).Value = rbManagement.Text;
}
else if (rbUser.Checked == true)
{
cmd.Parameters.Add("@UserType", SqlDbType.NVarChar).Value = rbUser.Text;
}
cmd.Parameters.Add("@UserId", SqlDbType.NVarChar).Value = txtUserId.Text;
cmd.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = txtUserName.Text;
cmd.Parameters.Add("@DepartmentId", SqlDbType.NVarChar).Value = txtDeptId.Text;
cmd.Parameters.Add("@DepartmentName", SqlDbType.NVarChar).Value = txtDeptName.Text;
cmd.Parameters.Add("@Password", SqlDbType.NVarChar).Value = txtPassword.Text;
cmd.Parameters.Add("@ScreenCode", SqlDbType.NVarChar).Value = dgvScreenDetails.Rows[i].Cells[0].Value;
cmd.Parameters.Add("@ScreenName", SqlDbType.NVarChar).Value = dgvScreenDetails.Rows[i].Cells[1].Value;

}
cmd.ExecuteNonQuery();
MessageBox.Show("Record Saved Successfully");

txtUserId.Text = "";
txtUserName.Text = "";
txtDeptId.Text = "";
txtDeptName.Text = "";
txtPassword.Text = "";
txtRePassword.Text = "";
if (rbAdmin.Checked == true)
{
rbAdmin.Checked = false;
}
else if (rbManagement.Checked == true)
{
rbManagement.Checked = false;
}
else if (rbUser.Checked == true)
{
rbUser.Checked = false;
}

conn.Close();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900