Click here to Skip to main content
15,887,683 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# solving any puzzle with Genetic Algorithms Pin
Sascha Lefèvre12-May-15 15:09
professionalSascha Lefèvre12-May-15 15:09 
QuestionMicrosoft Dynamic AX 2012 Pin
shabeercp11-May-15 19:10
shabeercp11-May-15 19:10 
SuggestionRe: Microsoft Dynamic AX 2012 Pin
Richard MacCutchan11-May-15 21:18
mveRichard MacCutchan11-May-15 21:18 
QuestionMVC3 - Linq query to View Pin
Member 1156707911-May-15 7:25
Member 1156707911-May-15 7:25 
AnswerRe: MVC3 - Linq query to View Pin
Atish Dipongkor11-May-15 7:48
professionalAtish Dipongkor11-May-15 7:48 
GeneralRe: MVC3 - Linq query to View Pin
Member 1156707911-May-15 7:57
Member 1156707911-May-15 7:57 
AnswerRe: MVC3 - Linq query to View Pin
F-ES Sitecore11-May-15 23:42
professionalF-ES Sitecore11-May-15 23:42 
QuestionUpdate in C# using SQL Server Database. Pin
Norris Chappell10-May-15 19:54
Norris Chappell10-May-15 19:54 
I have a datagridview that I changed the name Jones to Brown in a row. Now I need to update my SqlServer table with that change.
I am using C# for the code and SqlServer 2010 for the database and SharePoint to display the data as a webpart.
I have read almost everything on the internet and can't seem to find an answer to my issue.
Datagridview

KeyPer Test

Name

Doe
Smith
Jones

I change a name in the Name column

KeyPer Test

Name

Doe
Smith
brown

I'm having trouble getting past this setting of the parameter for ID.
It is giving me am error: The name ID does not exist in the current content.

Code Behind

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace StaffingWebParts.KeyPerTest
{
    public partial class KeyPerTestUserControl : UserControl
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLStaffingConn"].ConnectionString);
        SqlCommand cmd = new SqlCommand();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataTable dt = new DataTable();
                

                dt.Columns.Add("Name");
                dt.Columns.Add("VDCIDIQ");
                dt.Columns.Add("VDCFFS");
                dt.Columns.Add("VDCHIM");
                dt.Columns.Add("VDCWEBHOSTING");
                dt.Columns.Add("VDCCWF");
                SqlDataReader myReader = null;
                SqlCommand cmd = new SqlCommand("SELECT distinct  Name, VDCIDIQ , VDCFFS, VDCHIM, VDCWEBHOSTING, VDCCWF  from CMS_Key_Personnel where Name <> '   ' order by  Name");
                cmd.Connection = conn;
                conn.Open();
                myReader = cmd.ExecuteReader();
                while (myReader.Read())
                {
                    DataRow dr = dt.NewRow();
                    dr[0] = myReader["Name"].ToString();
                    dr[1] = myReader["VDCIDIQ"].ToString();
                    dr[2] = myReader["VDCFFS"].ToString();
                    dr[3] = myReader["VDCHIM"].ToString();
                    dr[4] = myReader["VDCWEBHOSTING"].ToString();
                    dr[5] = myReader["VDCCWF"].ToString();
                    dt.Rows.Add(dr);
                }
                
                gvKeyPersonnel.DataSource = dt;
                gvKeyPersonnel.DataBind();
                conn.Close();
            }
        }

       protected void Button_Update(object sender, EventArgs e)
        
       {
         using(SqlCommand cmd = new SqlCommand())
        {
                     
          cmd.Connection = conn;
          conn.Open();
          cmd.CommandText = "UPDATE SP2010_EDCStaffing_AppDB.dbo.CMS_Key_Personnel  SET  Name = @Name  WHERE ID = @id";
          cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 75);



          cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
          
          
          cmd.ExecuteNonQuery();
          conn.Close();
        }
        }
        }
        }

AnswerRe: Update in C# using SQL Server Database. Pin
Agent__00710-May-15 20:27
professionalAgent__00710-May-15 20:27 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell10-May-15 21:03
Norris Chappell10-May-15 21:03 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell10-May-15 21:07
Norris Chappell10-May-15 21:07 
GeneralRe: Update in C# using SQL Server Database. Pin
Agent__00710-May-15 22:12
professionalAgent__00710-May-15 22:12 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell11-May-15 5:49
Norris Chappell11-May-15 5:49 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell11-May-15 6:54
Norris Chappell11-May-15 6:54 
GeneralRe: Update in C# using SQL Server Database. Pin
Mycroft Holmes11-May-15 14:43
professionalMycroft Holmes11-May-15 14:43 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell11-May-15 15:22
Norris Chappell11-May-15 15:22 
GeneralRe: Update in C# using SQL Server Database. Pin
Mycroft Holmes11-May-15 16:09
professionalMycroft Holmes11-May-15 16:09 
AnswerRe: Update in C# using SQL Server Database. Pin
Agent__00711-May-15 17:20
professionalAgent__00711-May-15 17:20 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell11-May-15 20:09
Norris Chappell11-May-15 20:09 
GeneralRe: Update in C# using SQL Server Database. Pin
Agent__00711-May-15 20:30
professionalAgent__00711-May-15 20:30 
GeneralRe: Update in C# using SQL Server Database. Pin
Mycroft Holmes11-May-15 22:32
professionalMycroft Holmes11-May-15 22:32 
GeneralRe: Update in C# using SQL Server Database. Pin
Pete O'Hanlon12-May-15 0:26
mvePete O'Hanlon12-May-15 0:26 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell12-May-15 4:27
Norris Chappell12-May-15 4:27 
GeneralRe: Update in C# using SQL Server Database. Pin
Pete O'Hanlon12-May-15 4:49
mvePete O'Hanlon12-May-15 4:49 
GeneralRe: Update in C# using SQL Server Database. Pin
Norris Chappell12-May-15 11:36
Norris Chappell12-May-15 11:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.