Click here to Skip to main content
15,905,325 members
Home / Discussions / C#
   

C#

 
AnswerRe: web controls in windows forms Pin
Pete O'Hanlon27-Jul-23 22:04
mvePete O'Hanlon27-Jul-23 22:04 
GeneralRe: web controls in windows forms Pin
Dave Kreskowiak28-Jul-23 8:45
mveDave Kreskowiak28-Jul-23 8:45 
AnswerRe: web controls in windows forms Pin
Gerry Schmitz28-Jul-23 5:19
mveGerry Schmitz28-Jul-23 5:19 
AnswerRe: web controls in windows forms Pin
pr1mem0ver29-Jul-23 21:13
pr1mem0ver29-Jul-23 21:13 
GeneralRe: web controls in windows forms Pin
OriginalGriff29-Jul-23 21:22
mveOriginalGriff29-Jul-23 21:22 
GeneralRe: web controls in windows forms Pin
pr1mem0ver30-Jul-23 10:32
pr1mem0ver30-Jul-23 10:32 
GeneralRe: web controls in windows forms Pin
OriginalGriff30-Jul-23 18:29
mveOriginalGriff30-Jul-23 18:29 
AnswerRe: web controls in windows forms Pin
Graeme_Grant19-Aug-23 15:10
mvaGraeme_Grant19-Aug-23 15:10 
QuestionKindly help me i tried to do it for 3 days but i could not solve it. Pin
Hillymalen26-Jul-23 20:18
Hillymalen26-Jul-23 20:18 
AnswerRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 20:26
mveOriginalGriff26-Jul-23 20:26 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
Hillymalen26-Jul-23 20:55
Hillymalen26-Jul-23 20:55 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 21:40
mveOriginalGriff26-Jul-23 21:40 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
Hillymalen26-Jul-23 22:00
Hillymalen26-Jul-23 22:00 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 22:08
mveOriginalGriff26-Jul-23 22:08 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
Hillymalen26-Jul-23 22:13
Hillymalen26-Jul-23 22:13 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
Ralf Meier26-Jul-23 22:35
mveRalf Meier26-Jul-23 22:35 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 22:47
mveOriginalGriff26-Jul-23 22:47 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 22:45
mveOriginalGriff26-Jul-23 22:45 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
Hillymalen26-Jul-23 23:23
Hillymalen26-Jul-23 23:23 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 23:40
mveOriginalGriff26-Jul-23 23:40 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 23:47
mveOriginalGriff26-Jul-23 23:47 
Questionc# Pin
Impana D patel24-Jul-23 0:54
Impana D patel24-Jul-23 0:54 
the data from the 1st row is getting saved to the database but the 2nd row is created dainamically so the data in the newly added dainamic rows data is not saving to the database, insted it giving this error Cry | :((


System.Exception: 'Violation of PRIMARY KEY constraint 'PK_Timesheet'. Cannot insert duplicate key in object 'dbo.Timesheet'. The duplicate key value is (2).
The statement has been terminated.


code:
protected void SaveButton_Click(object sender, EventArgs e)
        {
            string EmpId = Session["EmpId"].ToString();
            string StrSQL = "";
            clsDB obj = new clsDB();

            // Get the maximum TaskID from the database
            StrSQL = "SELECT MAX(TaskID) FROM Timesheet";
            object maxTaskID = obj.GetScalar(StrSQL);
            int TaskID = maxTaskID != DBNull.Value ? Convert.ToInt32(maxTaskID) + 1 : 1;

            // Save the data from the first row
            StrSQL = "INSERT INTO Timesheet ";
            StrSQL += "VALUES('" + EmpId + "','" + TaskID + "','" + txttask.Text + "','" + txttaskdate.Text + "', ";
            StrSQL += "'" + txtDescription.Text + "', '" + txttimetaken.Text + "')";

            Result = Convert.ToInt32(obj.ExecuteNonQuery(StrSQL));
            if (Result == 1)
            {
                string script = "alert('Data saved Successfully')";
                ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
            }
            string message = "";
            int currentTaskID = TaskID;

            StrSQL = "INSERT INTO Timesheet ("+" EmployeeId, TaskId, TaskDate, TaskName, Description, TimeTaken) VALUES ";
            StrSQL += "('" + EmpId + "','" + currentTaskID + "','";
            foreach (TextBox textBox in pnlTextBoxes.Controls.OfType<TextBox>())
            {
                StrSQL += textBox.Text + "','";
            }
            StrSQL = StrSQL.Substring(0, StrSQL.Length - 2) + ");"; // Remove the extra ',' and add the closing parenthesis
            Result = Convert.ToInt32(obj.ExecuteNonQuery(StrSQL));
            ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('" + message + "');", true);

        }
    }

AnswerRe: c# Pin
Richard Deeming24-Jul-23 1:08
mveRichard Deeming24-Jul-23 1:08 
AnswerRe: c# Pin
Richard MacCutchan24-Jul-23 1:33
mveRichard MacCutchan24-Jul-23 1:33 
AnswerRe: c# Pin
OriginalGriff24-Jul-23 1:55
mveOriginalGriff24-Jul-23 1:55 

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.