0

hi,
it show me this error Incorrect syntax near the keyword 'Select' to make to clear Employee ID in this case is FK in the table (Attendance detail) and the other thing is i am using Data Grid View from another table(Employee information) to Show the list of the staff in my form. then i want to transfer each selected cell value from Data Grid View to attendance detail table. 10q

 private void time_in_Click(object sender, EventArgs e)
    {
        employee_InformationDataGridView.SelectedCells[0].Style.ForeColor = Color.Green;
            time_in.Enabled = false;
            time_out.Enabled = true;
            con = new SqlConnection(GlobalClass.conn);
            con.Open();
            SqlCommand cmd = new SqlCommand("Insert into Attendancedetail  Values(" + "Select Employee from EmployeeInformation where FullName = ' Selected Cells Value'" + ",'" + null + "','" + null + "','" + null + "','" + null + "','" + DateTime.Now.ToLongTimeString() + "'," + null + ")", con);
            int i = cmd.ExecuteNonQuery();
            MessageBox.Show(i.ToString() + " record inserted");

    }

Edited by Reverend Jim: Fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by zid8ne
0

script sample for inserting data using select statement

INSERT INTO [tablename]
(
column1,
column2
)
SELECT
column1,
column2
FROM [sourcetablename]

Edited by zid8ne: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.