stringbuilder를 사용하여 프로세스를 단순화하려고 시도했지만 오류가 표시되고 stringbuilder 또는 코드 구문과 관련된 문제인지 이해할 수 없습니다.쿼리를 구문 분석하는 동안 오류가 발생했습니다. [Token line number = 1 ...]
코드 :
if (dataGridView4.RowCount == 0)
{
MessageBox.Show("Attendance form is empty");
}
else
{
//string att;
int a = dataGridView4.RowCount;
string[] s = new string[a];
for (int i = 0; i < a; i++)
{
if (dataGridView4.Rows[i].Cells[1].Selected)
{
s[i] = "Present";
}
else
{
s[i] = "Absent";
}
}
string[] s1 = new string[a];
for (int i = 0; i < a; i++)
{
s1[i] = dataGridView4.Rows[i].Cells[0].Value.ToString();
}
string date = dateTimePicker1.Value.ToString("dd-MM-yyyy");
StringBuilder command = new StringBuilder();
for (int i = 0; i < a; i++)
{
command.Append("INSERT into Attendance (att_date, emp_code, is_present) values ('" + date + "','" + s1[i] + "','" + s[i] + "')");
}
SqlCeConnection conn = new SqlCeConnection(@"Data Source=C:\Users\admin\documents\visual studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\hotel.sdf");
conn.Open();
SqlCeCommand cmd = new SqlCeCommand(command.ToString(),conn);
cmd.ExecuteNonQuery();
MessageBox.Show("Attendance Added");
나를 위의 코드는 간단하게 알려 주시기 바랍니다 수 있도록 어떤 제안이 또한 경우,이 오류를 해결하는 데 도움이 바랍니다.
미리 감사드립니다.
을 다음 당신은 할 수 있습니다 각 격자 행에 대해
, 나는 내가 이것 때문에 오류를 얻고, SQL 서버 컴팩트를 사용하고? stringbuilder 대신 for 루프를 사용해야합니까? –