Click here to Skip to main content
15,914,160 members
Home / Discussions / C#
   

C#

 
QuestionToggling UI Elements (ToolStrip and MenuStrip Items and the Like) Pin
Matt U.29-Jul-10 16:53
Matt U.29-Jul-10 16:53 
AnswerRe: Toggling UI Elements (ToolStrip and MenuStrip Items and the Like) Pin
Jimmanuel30-Jul-10 3:31
Jimmanuel30-Jul-10 3:31 
GeneralRe: Toggling UI Elements (ToolStrip and MenuStrip Items and the Like) Pin
Matt U.30-Jul-10 8:42
Matt U.30-Jul-10 8:42 
GeneralRe: Toggling UI Elements (ToolStrip and MenuStrip Items and the Like) Pin
Matt U.30-Jul-10 12:03
Matt U.30-Jul-10 12:03 
GeneralRe: Toggling UI Elements (ToolStrip and MenuStrip Items and the Like) Pin
Jimmanuel31-Jul-10 6:39
Jimmanuel31-Jul-10 6:39 
QuestionNHibernate CreateSqlQuery and addEntity Pin
Matt Cavanagh29-Jul-10 16:22
Matt Cavanagh29-Jul-10 16:22 
QuestionUsing RasGetEntryProperties in .NET CF Pin
notsotragichero29-Jul-10 9:49
notsotragichero29-Jul-10 9:49 
QuestiondatagridView1_CellContentClick Problem Pin
MumbleB29-Jul-10 6:27
MumbleB29-Jul-10 6:27 
Hi guys. I am having a problem with the above. I am trying to update the changes made to the gridview back to the database but for some reason I get a "Data Type mismatch in criteria expression" OleDbException. I have tried a number of updates but nothing seems to work. Below is the code I am using. I have delete section which works fine. Just the Edit portion that doesn't work. Can somebody please advise what I am missing here?

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    int currentRow = int.Parse(e.RowIndex.ToString());
    int rowint = 0;
    string sql = "SELECT TimesheetDetailID, EmployeeID, TSProjectCodeID, TimeSheetDate, HoursWorked, TaskCode, Notes from tblTimesheetDetails WHERE TimesheetDetailID ='" + rowint + "'";
    string empID = dataGridView1[1, currentRow].Value.ToString();
    string projcode = dataGridView1[2, currentRow].Value.ToString();
    string timedate = Convert.ToString(dataGridView1[3, currentRow].Value.ToString());
    double hrs = Convert.ToDouble(string.Format("{0:f}", (dataGridView1[4, currentRow].Value.ToString())));
    string taskcode = dataGridView1[5, currentRow].Value.ToString();
    string notes = dataGridView1[6, currentRow].Value.ToString();
    OleDbDataAdapter da = new OleDbDataAdapter(sql, conn);
    OleDbCommandBuilder cmb = new OleDbCommandBuilder(da);
    da.Fill(dataTable);
    string updateString = "Update tblTimesheetDetails SET EmployeeID ='" + empID + "', TimesheetID ='" + "" + "', TSProjectID ='" + projcode + "', TimeSheetDate ='" + timedate + "', HoursWorked ='" + hrs + "',TaskCode ='" + taskcode + "', Notes ='" + notes + "' WHERE TimesheetDetailID ='" + rowint + "'";

    try
    {
        conn.Open();
        string timesheetString = dataGridView1[0, currentRow].Value.ToString();
        rowint = int.Parse(timesheetString);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message.ToString());
    }

    if (dataGridView1.Columns[e.ColumnIndex] == deleteButton && currentRow >= 0)
    {

        string queryDeleteString = "DELETE FROM tblTimesheetDetails where TimesheetDetailID = " + rowint + "";
        OleDbCommand sqlDelete = new OleDbCommand();
        sqlDelete.CommandText = queryDeleteString;
        sqlDelete.Connection = conn;
        sqlDelete.ExecuteNonQuery();
    }



    else if (dataGridView1.Columns[e.ColumnIndex] == editButton && currentRow >= 0)
    {

        try
        {
            if (dataTable.Rows.Count != 0)
            {
                dataTable.Rows[rowint]["EmployeeID"] = empID;
                dataTable.Rows[rowint]["TimesheetID"] = 0;
                dataTable.Rows[rowint]["TSProjectCodeID"] = projcode;
                dataTable.Rows[rowint]["TaskCode"] = taskcode;
                dataTable.Rows[rowint]["TimeSheetDate"] = timedate;
                dataTable.Rows[rowint]["HoursWorked"] = hrs;
                dataTable.Rows[rowint]["Notes"] = notes;
                dataTable.AcceptChanges();
                da.Update(dataTable);
            }
        }
        catch (OleDbException exx)
        {
            MessageBox.Show(exx.Message.ToString());
        }

    }
        conn.Close();
        GetDataView();
}

Excellence is doing ordinary things extraordinarily well.

AnswerRe: datagridView1_CellContentClick Problem Pin
I Believe In GOD29-Jul-10 6:56
I Believe In GOD29-Jul-10 6:56 
GeneralRe: datagridView1_CellContentClick Problem Pin
MumbleB29-Jul-10 7:05
MumbleB29-Jul-10 7:05 
AnswerRe: datagridView1_CellContentClick Problem Pin
Mycroft Holmes29-Jul-10 17:21
professionalMycroft Holmes29-Jul-10 17:21 
GeneralRe: datagridView1_CellContentClick Problem Pin
MumbleB4-Aug-10 2:39
MumbleB4-Aug-10 2:39 
QuestionProblem with pc to pc Voice chat on LAN using h323 protocol. Pin
88Rocker29-Jul-10 5:46
88Rocker29-Jul-10 5:46 
AnswerReason for my vote of 1 Pin
OriginalGriff29-Jul-10 6:04
mveOriginalGriff29-Jul-10 6:04 
QuestionGive .NET Compiled Assemblly DLL StrongName Pin
I Believe In GOD29-Jul-10 5:33
I Believe In GOD29-Jul-10 5:33 
AnswerRe: Give .NET Compiled Assemblly DLL StrongName Pin
Ennis Ray Lynch, Jr.29-Jul-10 5:35
Ennis Ray Lynch, Jr.29-Jul-10 5:35 
GeneralRe: Give .NET Compiled Assemblly DLL StrongName Pin
I Believe In GOD29-Jul-10 5:54
I Believe In GOD29-Jul-10 5:54 
GeneralRe: Give .NET Compiled Assemblly DLL StrongName PinPopular
Nagy Vilmos29-Jul-10 5:59
professionalNagy Vilmos29-Jul-10 5:59 
GeneralRe: Give .NET Compiled Assemblly DLL StrongName Pin
I Believe In GOD29-Jul-10 6:02
I Believe In GOD29-Jul-10 6:02 
GeneralRe: Give .NET Compiled Assemblly DLL StrongName Pin
Eddy Vluggen29-Jul-10 6:25
professionalEddy Vluggen29-Jul-10 6:25 
GeneralRe: Give .NET Compiled Assemblly DLL StrongName [modified] Pin
I Believe In GOD29-Jul-10 6:38
I Believe In GOD29-Jul-10 6:38 
GeneralRe: Give .NET Compiled Assemblly DLL StrongName Pin
Eddy Vluggen29-Jul-10 7:15
professionalEddy Vluggen29-Jul-10 7:15 
GeneralRe: Give .NET Compiled Assemblly DLL StrongName Pin
I Believe In GOD29-Jul-10 7:34
I Believe In GOD29-Jul-10 7:34 
GeneralRe: Give .NET Compiled Assemblly DLL StrongName Pin
Eddy Vluggen29-Jul-10 8:43
professionalEddy Vluggen29-Jul-10 8:43 
GeneralRe: Give .NET Compiled Assemblly DLL StrongName Pin
I Believe In GOD29-Jul-10 7:38
I Believe In GOD29-Jul-10 7:38 

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.