Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ocks编译为try/catch/finally。与以前一样太长我不认为使用块会提高性能,因为您可能认为使用块编译为try/catch/finally。与以前一样太长 private static void UpdateVolunteer(string _C#_.net_Sql Server 2008_Stored Procedures - Fatal编程技术网

C# ocks编译为try/catch/finally。与以前一样太长我不认为使用块会提高性能,因为您可能认为使用块编译为try/catch/finally。与以前一样太长 private static void UpdateVolunteer(string

C# ocks编译为try/catch/finally。与以前一样太长我不认为使用块会提高性能,因为您可能认为使用块编译为try/catch/finally。与以前一样太长 private static void UpdateVolunteer(string ,c#,.net,sql-server-2008,stored-procedures,C#,.net,Sql Server 2008,Stored Procedures,ocks编译为try/catch/finally。与以前一样太长我不认为使用块会提高性能,因为您可能认为使用块编译为try/catch/finally。与以前一样太长 private static void UpdateVolunteer(string volID, string volName, string volZone, string volStreet, int volSex, DateTime volBirthday, int volHomePhone, int volWor


ocks编译为try/catch/finally。与以前一样太长我不认为使用块会提高性能,因为您可能认为
使用
块编译为try/catch/finally。与以前一样太长
 private static void UpdateVolunteer(string volID, string volName, string volZone,
 string volStreet, int volSex, DateTime volBirthday, int volHomePhone, 
 int volWorkPhone, int volMobile1, int volMobile2, string volEmail, 
 string volJob, string volAffiliation, int volEducation, 
 string volEducationPlace, string volEducationDepartment, int volInteresting, 
 int Team_ID, string volNotes)
 {
    try
    {
       SqlCommand com = new SqlCommand("UpdateVolunteers", con);

       com.Parameters.Add("@Vol_ID", SqlDbType.Int).Value = volID;
       com.Parameters.Add("@Vol_Name", SqlDbType.NVarChar, 50).Value = volName;
       com.Parameters.Add("@Vol_Zone", SqlDbType.NVarChar, 50).Value = volZone;
       com.Parameters.Add("@vol_street", SqlDbType.NVarChar, 50).Value = volStreet;
       com.Parameters.Add("@Vol_Sex", SqlDbType.Int).Value = volSex;
       com.Parameters.Add("@Vol_Date_of_Birth", SqlDbType.DateTime).Value = volBirthday;
       com.Parameters.Add("@Vol_Home_Phone", SqlDbType.Int).Value = volHomePhone;
       com.Parameters.Add("@Vol_Work_Phone", SqlDbType.Int).Value = volWorkPhone;
       com.Parameters.Add("@Vol_Mobile1", SqlDbType.Int).Value = volMobile1;
       com.Parameters.Add("@Vol_Mobile2", SqlDbType.Int).Value = volMobile2;
       com.Parameters.Add("@Vol_Email", SqlDbType.NVarChar, 50).Value = volEmail;
       com.Parameters.Add("@Vol_Job", SqlDbType.NVarChar, 50).Value = volJob;
       com.Parameters.Add("@Vol_Affiliation", SqlDbType.NVarChar, 50).Value = volAffiliation;
       com.Parameters.Add("@vol_Education", SqlDbType.Int).Value = volEducation;
       com.Parameters.Add("@vol_Education_Place", SqlDbType.NVarChar, 50).Value = volEducationPlace;
       com.Parameters.Add("@vol_Education_Department", SqlDbType.NVarChar, 50).Value = volEducationDepartment;
       com.Parameters.Add("@vol_Interesting", SqlDbType.Int).Value = volInteresting;
       com.Parameters.Add("@vol_Notes", SqlDbType.NVarChar, 50).Value = volNotes;
       com.Parameters.Add("@Team_ID", SqlDbType.Int);
       com.Parameters["@Team_ID"].Value = Team_ID;

       com.CommandType = System.Data.CommandType.StoredProcedure;
       if (con.State != ConnectionState.Open)
          con.Open();
          com.ExecuteNonQuery();
          con.Close();
   }
   catch (SqlException sqlEx)
   {
      if (con.State == ConnectionState.Open)
         con.Close();
         throw sqlEx;
   }
}
public void showVolunteers(int x)
    {
        SqlCommand com = new SqlCommand("SELECT [Vol_ID]
  ,[Vol_Name]
  ,[Vol_Zone]
  ,[vol_street]
  ,[Vol_Sex]
  ,[vol_Age]
  ,[Vol_Date_of_Birth]
  ,[Vol_Home_Phone]
  ,[Vol_Work_Phone]
  ,[Vol_Mobile1]
  ,[Vol_Mobile2]
  ,[Vol_Email]
  ,[Vol_Job]
  ,[Vol_Affiliation]
  ,[vol_Education]
  ,[vol_Education_Place]
  ,[vol_Education_Department]
  ,[vol_Interesting]
  ,[vol_Hours]
  ,[vol_Notes]
  ,[Team_ID]
  FROM [VolunteersAffairs].[dbo].[Personal_Info]", con);
        SqlDataAdapter da = new SqlDataAdapter();
        DataSet dats = new DataSet();
        da.SelectCommand = com;
        da.Fill(dats, "Personal_Info");
        dataGridViewX1.DataSource = dats.Tables["Personal_Info"];
        dataGridViewX1.Columns[2].DefaultCellStyle.NullValue = "Nothing";
        updateComboBox.SelectedIndex = updateComboBox.Items.Count - 1;
        if (x != -1)
        {
            dataGridViewX1.Rows[x].Selected = true;
            dataGridViewX1.CurrentCell = dataGridViewX1[0, x];
        }
        labelItem1.Text = "Number of Volunteers = " + dataGridViewX1.Rows.Count;
        int X = 0, Y = 0;
        foreach (DataGridViewRow n in dataGridViewX1.Rows)
        {
            if (n.Cells[5].Value.ToString() == "Male")
                X++;
            else
                Y++;
        }
        labelItem2.Text = "   |   Number of Males = " + X + " |Number of Female = " + Y;

        //When I put the following as a comment the update is so fast, else very slowly.
       //This operation takes the birthday of volunteers and calculate the age for every one. 
       //And calculate the age in runTime and the value of the column in database is null and always be.
        #region the problem has been detected here
        DateTime brithday;
        for (int i = 0; i < dataGridViewX1.Rows.Count; i++)
        {
            brithday = (DateTime)dataGridViewX1[6, i].Value;
            TimeSpan age = DateTime.Today - brithday;
            dataGridViewX1[7, i].Value = age.Days / 365;
        }
        #endregion

   }
using (var connection = new SqlConnection(connectionString))
{
  using (var command = new SqlCommand("UpdateVolunteers", connection))
  {
    command.Parameters.AddWithValue("@Vol_ID", volID);
    // other paramters...

    connection.Open();
    command.ExecuteNonQuery();
  }
}