Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
N

Norris Chappell

@Norris Chappell
About
Posts
104
Topics
13
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Trying to prevent the first dropdownlist value changing my database field unless I need to in C#
    N Norris Chappell

    I inserted that line into my code but I still don't see the correct dropdownlist value but only the first value. Do I need to do something with that line of code elsewhere in my code? dd.DataBind(); string value = DataBinder.Eval(e.Row.DataItem, "SAPLeader").ToString(); dd.SelectedIndex = dd.Items.IndexOf(dd.Items.FindByText("value")); I inserted some breakpoints and I can see the correct value however, then I do an UPDATE it takes the first value in my dropdownlist and replaces the current value. Thanks,

    ASP.NET csharp database help

  • Trying to prevent the first dropdownlist value changing my database field unless I need to in C#
    N Norris Chappell

    I changed it to dd.SelectedValue = value; It still doesn't work. The issue is that once I select EDIT the current value in the SAPLeader field goes away and the dropdownlist is now showing the first value and that is the one it choses when you select UPDATE. What I would like it do is to select the right dropdown value when the dropdownlist loads.

    ASP.NET csharp database help

  • Trying to prevent the first dropdownlist value changing my database field unless I need to in C#
    N Norris Chappell

    Hi, I am having an issue with my dropdownlist taking the first value in my list even though I didn't change that field. When I select EDIT it gives me that row that I need to edit but the dropdownlist shows the first value which is not correct. When I do gvAccountStaff_RowUpdating the dropdown changes to the first value. I would like to retain and show the correct database value.

    using System;
    using System.IO;
    using System.Configuration;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Drawing;
    using System.Data.SqlClient;
    using System.Web.UI;
    using System.Data.OleDb;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls.WebParts;

    namespace StaffingWebParts.AccountStaffMaintenance
    {
    public partial class AccountStaffMaintenanceUserControl : UserControl
    {
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLStaffingConn"].ConnectionString);
    SqlCommand cmd = new SqlCommand();

        protected void Page\_Load(object sender, EventArgs e)
        {
            lblMsg.Text = "";
            if (!Page.IsPostBack)
            {
                
                BindSubjectData();
                
            }
    
        }
       
        //call to bind gridview
       
        public class DropDownData
        {
            public DropDownData(int id, string displaytext)
            {
                iD = id;
                text = displaytext;
            }
            int iD;
            public int ID
            {
                get { return iD; }
                set { iD = value; }
            }
            string text;
            public string Text
            {
                get { return text; }
                set { text = value; }
            }
        }
        protected void gvAccountStaff\_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            
    
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                   
                    Control ctrl = e.Row.FindControl("ddlType");
                    if (ctrl != null)
                    {
                        conn.Close();
                        DropDownList dd = ctrl as DropDownList;
                        List lst = new List();
                        SqlCommand cmd = new SqlCommand("SELECT ID, Last
    
    ASP.NET csharp database graphics design security

  • Trying to prevent the first dropdownlist value changing my database field unless I need to in C#
    N Norris Chappell

    Hi, I was able to solve my issue.

    string value = DataBinder.Eval(e.Row.DataItem, "SAPLeader").ToString();
    dd.SelectedValue = value;
    dd.SelectedIndex = dd.Items.IndexOf(dd.Items.FindByText(value.ToString()));

    This is the fixed. :)

    ASP.NET csharp database help

  • C# code is only inserting a few records.
    N Norris Chappell

    Thanks that worked. Really appreciated it.

    C# csharp database

  • C# code is only inserting a few records.
    N Norris Chappell

    That worked but if no record is found for someone can I just skip it and continue? Your revised sql does exactly what I wanted to do except it gives an error and the users wouldn't know what to do with it. The problem is that we have some employee that are suppliers and others direct and vise versa. this is what I am getting. No staff tracking record found for resource 'ALISON GREEN'. Cannot insert the value NULL into column 'StaffTrackingID', table 'SP2010_EDCStaffing_AppDB.dbo.StaffTrackingFTEData'; column does not allow nulls. INSERT fails. The statement has been terminated. The Field in StaffTracking to determine if a person is a direct or Supplier is PersonnelResourceType. I changed the above code to include in the where clause SELECT @StaffTrackingID = ID FROM StaffTracking WHERE CATWResourceName = @Name and PersonnelResourceType = 'Supplier'; but still getting that message.

    C# csharp database

  • C# code is only inserting a few records.
    N Norris Chappell

    Richard, I updated my sql query and it is giving me this error: (Must declare the scalar variable "@StaffTrackingID")

    protected void SubmitButton_Click(object sender, EventArgs e)
    {

                const string Query = "IF NOT EXISTS (SELECT StaffTrackingID, Period FROM StaffTrackingFTEData where StaffTrackingID = @StaffTrackingID and Period = @Period) INSERT INTO StaffTrackingFTEData (\[StaffTrackingID\], \[EstimateHours\], \[EstimateFTE\], \[ActualHours\], \[ActualFTE\],\[Comment\], \[CommentBy\], \[Period\]) VALUES ((Select StaffTracking.ID From StaffTracking where StaffTracking.CATWResourceName = @Name), @Estimatehours, @EstimateFTE, @ActualHours, @ActualFTE, @Comment, @CommentBy, @Period)";
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings\["SQLStaffingConn"\].ConnectionString);
    
                using (SqlCommand command = new SqlCommand(Query, conn))
                {
                    conn.Open();
                    command.Parameters.AddWithValue("@StaffTrackingID", SqlDbType.Int).Direction = ParameterDirection.Output;
                    foreach (GridViewRow row in gvCATW.Rows)
                    {
    
    
                        command.Parameters.AddWithValue("@Name", ((TextBox)row.FindControl("txtName")).Text);
                        command.Parameters.AddWithValue("@EstimateHours", ((TextBox)row.FindControl("txtEstimateHours")).Text);
                        command.Parameters.AddWithValue("@EstimateFTE", ((TextBox)row.FindControl("txtEstimateFTE")).Text);
                        command.Parameters.AddWithValue("@ActualHours", ((TextBox)row.FindControl("txtHours")).Text);
                        command.Parameters.AddWithValue("@ActualFTE", ((Label)row.FindControl("Label1")).Text);
                        command.Parameters.AddWithValue("@Comment", ((TextBox)row.FindControl("txtComment")).Text);
                        command.Parameters.AddWithValue("@CommentBy", ((TextBox)row.FindControl("txtCommentBy")).Text);
                        command.Parameters.AddWithValue("@Period", ((TextBox)row.FindControl("txtPeriod")).Text);
    
    
                        command.ExecuteNonQuery();
                        command.Parameters.Clear();
                    }
                }
    
            }
    
    C# csharp database

  • C# code is only inserting a few records.
    N Norris Chappell

    Can you provide a snippet of what you are talking about? So this is not correct?

    protected void SubmitButton_Click(object sender, EventArgs e)
    {

                const string Query = "INSERT INTO StaffTrackingFTEData (\[StaffTrackingID\], \[EstimateHours\], \[EstimateFTE\], \[ActualHours\], \[ActualFTE\],\[Comment\], \[CommentBy\], \[Period\]) VALUES ((Select StaffTracking.ID From StaffTracking where StaffTracking.CATWResourceName = @Name), @Estimatehours, @EstimateFTE, @ActualHours, @ActualFTE, @Comment, @CommentBy, @Period)";
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings\["SQLStaffingConn"\].ConnectionString);
    
                using (SqlCommand command = new SqlCommand(Query, conn))
                {
                    conn.Open();
                    command.Parameters.AddWithValue("@StaffTrackingID", SqlDbType.Int).Direction = ParameterDirection.Output;
                    foreach (GridViewRow row in gvCATW.Rows)
                    {
    
    
                        command.Parameters.AddWithValue("@Name", ((TextBox)row.FindControl("txtName")).Text); 
    

    .....
    .....
    .....

    C# csharp database

  • C# code is only inserting a few records.
    N Norris Chappell

    command.Parameters.AddWithValue("@StaffTrackingID", SqlDbType.Int).Direction = ParameterDirection.Output; If I didn't declare that variable it was giving me an error that I needed to declare it.

    C# csharp database

  • C# code is only inserting a few records.
    N Norris Chappell

    The Period(yyyy-MM-01) that is when the spreadsheet was produced. So if the spreadsheet was this month it would be 2015-06-01 and so forth. Right now it doesn't matter which spreadsheet I run the period is the same.

    C# csharp database

  • C# code is only inserting a few records.
    N Norris Chappell

    take away IF NOT EXISTS (SELECT * FROM StaffTrackingFTEData) I get " Cannot insert the value NULL into column 'StaffTrackingID', table 'SP2010_EDCStaffing_AppDB.dbo.StaffTrackingFTEData'; column does not allow nulls. INSERT fails.

    C# csharp database

  • C# code is only inserting a few records.
    N Norris Chappell

    Thanks. Just set the values beforehand?

    C# csharp database

  • C# code is only inserting a few records.
    N Norris Chappell

    So the "IF NOT EXISTS (SELECT * FROM StaffTrackingFTEData)" is not needed? The reason I put that in was to eliminate duplicates. What is they submitted several times. I don't want the same data in there several times.

    C# csharp database

  • C# code is only inserting a few records.
    N Norris Chappell

    Okay I took your advise and change my code and Parameterized my queries. I am now able to see all of my rows in the SQL database. However, I got a question for you? I need to have the users supply the period instead of it being generated in the code. Is there a way to do that Inline?

    C# csharp database

  • C# code is only inserting a few records.
    N Norris Chappell

    It should be inserting each row in my GridViewRow. 251 rows. Presently I have only 104 rows.

    protected void SubmitButton_Click(object sender, EventArgs e)
    {

                const string Query = "IF NOT EXISTS (SELECT \* FROM StaffTrackingFTEData) INSERT INTO StaffTrackingFTEData (\[StaffTrackingID\], \[EstimateHours\], \[EstimateFTE\], \[ActualHours\], \[ActualFTE\],\[Comment\], \[CommentBy\], \[Period\]) VALUES ((Select StaffTracking.ID From StaffTracking where StaffTracking.CATWResourceName = @Name), @Estimatehours, @EstimateFTE, @ActualHours, @ActualFTE, @Comment, @CommentBy, @Period)";
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings\["SQLStaffingConn"\].ConnectionString);
    
                using (SqlCommand command = new SqlCommand(Query, conn))
                {
                    conn.Open();
                    command.Parameters.AddWithValue("@StaffTrackingID", SqlDbType.Int).Direction = ParameterDirection.Output;
                    foreach (GridViewRow row in gvCATW.Rows)
                    {
    
    
                        command.Parameters.AddWithValue("@Name", ((TextBox)row.FindControl("txtName")).Text);
                        command.Parameters.AddWithValue("@EstimateHours", ((TextBox)row.FindControl("txtEstimateHours")).Text);
                        command.Parameters.AddWithValue("@EstimateFTE", ((TextBox)row.FindControl("txtEstimateFTE")).Text);
                        command.Parameters.AddWithValue("@ActualHours", ((TextBox)row.FindControl("txtHours")).Text);
                        command.Parameters.AddWithValue("@ActualFTE", ((Label)row.FindControl("Label1")).Text);
                        command.Parameters.AddWithValue("@Comment", ((TextBox)row.FindControl("txtComment")).Text);
                        command.Parameters.AddWithValue("@CommentBy", ((TextBox)row.FindControl("txtCommentBy")).Text);
                        command.Parameters.AddWithValue("@Period", ((TextBox)row.FindControl("txtPeriod")).Text);
    
    
                        command.ExecuteNonQuery();
                        command.Parameters.Clear();
                    }
                }
    
            }
    
    //protected void SubmitButton\_Click(object sender, EventArgs e)
    
    C# csharp database

  • Trying to sum several fields into a total field
    N Norris Chappell

    Pete, I not for sure how to use this code. Can you let me know what I need to do? I still getting the error for the 4 fields. The fields do not exist in the current context.

    C# csharp database linq graphics design

  • Trying to sum several fields into a total field
    N Norris Chappell

    It is what I have in my asp. Did I not set it properly?

    C# csharp database linq graphics design

  • Trying to sum several fields into a total field
    N Norris Chappell

    Hi, I not sure how to use this code? Please let me know if I need to make changes to it?

    C# csharp database linq graphics design

  • Trying to sum several fields into a total field
    N Norris Chappell

    I getting that error that The name 'Q1IntProc' does not exist in the current context. So I should have an if statement for each field that I am summing? So what goes here textBox.Text?

    C# csharp database linq graphics design

  • Trying to sum several fields into a total field
    N Norris Chappell

    Hi Everyone I finally figured it out. I didn't need to do it in C# after all. I modified my SQL to sum the fields I needed. I want to thank everyone that contributed.

    C# csharp database linq graphics design
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups