コード例 #1
0
 private void btnquerycode_Click(object sender, EventArgs e)
 {
     try
     {
         string sql = string.Format("select * from Pinfo where P_CODE like '%{0}%'and P_info like '%{1}%'", cbCode.Text, txtinfo.Text);
         SqlHelper.GetReader(sql);
         List <Pinfo_class> info = new List <Pinfo_class>();
         foreach (Pinfo_class item in SqlHelper.GetReader(sql))
         {
             Pinfo_class pclass = new Pinfo_class()
             {
                 P_Code   = item.P_Code,
                 P_Info   = item.P_Info,
                 P_Answer = item.P_Answer
             };
             info.Add(pclass);
         }
         this.dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True; //自动换行
         this.dataGridView1.DataSource = info;
     }
     catch (Exception ex)
     {
         MessageBox.Show("异常抛出\n" + ex, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtcode.TextLength == 0)
            {
                MessageBox.Show("请输入错误代码!!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.txtcode.Focus();
                return;
            }
            else if (txtinfo.TextLength == 0)
            {
                MessageBox.Show("请输入错误提示信息!!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.txtinfo.Focus();
                return;
            }
            else if (txtanswer.TextLength == 0)
            {
                MessageBox.Show("请输入解决方法!!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.txtanswer.Focus();
                return;
            }

            List <Pinfo_class> info = new List <Pinfo_class>();

            Pinfo_class objinfo = new Pinfo_class()
            {
                P_Code   = txtcode.Text.Trim(),
                P_Info   = txtinfo.Text.Trim(),
                P_Answer = txtanswer.Text.Trim()
            };

            info.Add(objinfo);
            string sql = "";

            try
            {
                foreach (Pinfo_class item in info)
                {
                    sql = string.Format("insert into Pinfo VALUES(newID(),'{0}','{1}','{2}')", item.P_Code, item.P_Info, item.P_Answer);
                    int result = SqlHelper.Update(sql);
                }

                this.dataGridView1.DataSource = info;
            }
            catch (Exception ex)
            {
                MessageBox.Show("未能完成该操作" + ex, "错误信息");
            }
        }