[ad_1]
C#
////////////////////////////////dataGridview not generated using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace ROEAS { public partial class Attendance : Form { SqlDataAdapter dap; DataTable dt; string a;//Here shows a error string b; public Attendance() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // d1.ConOpen(); // dt = d1.DisplayGrid("select emp_code,name,department from employee"); dataGridView1.DataSource = dt; // d1.ConClose(); generate(); //data(); int t; for (t = 0; t <= dataGridView1.Columns.Count - 1; t++) { dataGridView1.Columns dataGridView1.Columns dataGridView1.Columns } data(); } private void Button3_Click(object sender, EventArgs e) { // d1.ConOpen(); int t; DateTime d; d = DateTime.Parse(a); string s = d.Month + "-" + d.Day + "-" + d.Year; for (t = 0; t <= dataGridView1.Rows.Count - 1; t++) { //d1.Delete("delete from attendence where no=" + dataGridView1.Rows } for (t = 0; t <= dataGridView1.Rows.Count - 1; t++) { // d1.Insert("Insert into attendance (att_date,emp_code,is_present) values('" + s + "'," + dataGridView1.Rows } MessageBox.Show("Complate Fill Attendence"); // d1.ConClose(); } private void button1_Click(object sender, EventArgs e) { } public void data() { //d1.ConOpen(); int t; int u; //DateTime dt1 ; string dt1 = ""; for (u = 3; u <= dataGridView1.Columns.Count - 5; u++) { dt1 = DateTime.Parse(dataGridView1.Columns[u].HeaderText).ToShortDateString(); DataTable dt = new DataTable(); // dt = d1.DisplayGrid("select * from attendence where convert(varchar,d,101)='" + dt1.ToString() + "'"); if (dt.Rows.Count > 0) { for (t = 0; t < dt.Columns.Count; t++) { if (dt.Rows { dataGridView1.Rows } else { dataGridView1.Rows } } } } //d1.ConClose(); //return 0; } public void generate() { DateTime i; DateTime j; int[] a = new int[4]; DataTable dt1=new DataTable(); // dt1 = d1.DisplayGrid("select convert(varchar,SDate,101) ,convert(varchar,EDate,101) from semester"); i = DateTime.Parse(dt1.Rows[0][0].ToString()); j = DateTime.Parse(dt1.Rows[0][1].ToString()); while (i.CompareTo(j) != 0) { DataGridViewCheckBoxColumn dg = new DataGridViewCheckBoxColumn(); dg.HeaderText = i.Day + "/" + i.Month + "/" + i.Year; dg.Width = 30; dataGridView1.Columns.Add(dg); i = i.Date.AddDays(1); } dataGridView1.Columns.Add("Total", "Total"); } private void dataGridView1_Scroll(object sender, ScrollEventArgs e) { int t; for (t = 0; t <= 1; t++) { dataGridView1.Columns } } private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { int i; int u; int k; for (i = 0; i <= dataGridView1.Rows.Count - 1; i++) { k = 0; for (u = 3; u <= dataGridView1.Columns.Count - 5; u++) { if (dataGridView1.Rows[i].Cells[u].Value != null) { k = k + 1; } } if (k == 0) { dataGridView1.Rows[i].Cells["Total"].Value = 0; } else { dataGridView1.Rows[i].Cells["Total"].Value = k; } } } private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { a = dataGridView1.Columns[e.ColumnIndex].HeaderText; b = e.ColumnIndex.ToString(); int t; for (t = 0; t <= dataGridView1.Columns.Count - 2; t++) { if (dataGridView1.Columns { dataGridView1.Columns dataGridView1.Columns } else { dataGridView1.Columns dataGridView1.Columns } } } private void ChkAll_CheckedChanged(object sender, EventArgs e) { if ((ChkAll.Checked)) { int t; for (t = 3; t <= dataGridView1.Columns.Count - 5; t++) { string g = dataGridView1.Columns DateTime d; d = DateTime.Parse(dataGridView1.Columns if (g.CompareTo(a) == 0) { int i; for (i = 0; i <= dataGridView1.Rows.Count - 1; i++) { dataGridView1.Rows[i].Cells } } } } else { int t; for (t = 3; t <= dataGridView1.Columns.Count - 5; t++) { DateTime d; d = DateTime.Parse(dataGridView1.Columns string g = dataGridView1.Columns if (g.CompareTo(a) == 0) { int i; for (i = 0; i <= dataGridView1.Rows.Count - 1; i++) { dataGridView1.Rows[i].Cells } } } } } private void CheckedListBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { } private void Attendance_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'logindbDataSet9.Attendance' table. You can move, or remove it, as needed. this.attendanceTableAdapter.Fill(this.logindbDataSet9.Attendance); } } }
解決策 1
まず、「a」を文字列として宣言しています。
次に、それを DateTime に解析するために以下のコードを記述します。
C#
d = DateTime.Parse(a);
解析する前に初期化する必要があります。
[ad_2]
コメント