实验1 问题定义与可行性研究
作者:3sbase | 发布时间:2016/3/27

 根据自己熟悉或感兴趣的领域,结合GIS,设定自己欲开发的系统,请从问题定义与可行性研究2个方面书写开发文档。
    建议格式:
      1 背景与意义
      2 现状分析
        存在的问题,GIS引入的必要性等。
      3 方案
        推荐几种方案,并从技术、经济、操作方面论文可行性,推荐一种较优的方案。

    在完成以上文档基础上,学习C#基础知识。
    尝试开发一个学生信息管理系统,能够实现学生信息的添加\删除\修改\查询等。
    基于sql server+C#

添加:

  private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection();               
                con.ConnectionString = "server=.;database=stu;Integrated Security=True";
                string sql = string.Format("insert  into basicinfo values('{0}','{1}','{2}','{3}','{4}','{5}','{6}') ",
                   txtID.Text.Trim(), txtName.Text.Trim(), txtSex.Text.Trim(), txtHome.Text.Trim(), txtQQ.Text.Trim(), txtTel.Text.Trim(),
                    txtEmail.Text.Trim());
                SqlCommand cmd = new SqlCommand(sql, con);
                con.Open();
                int count = (int)cmd.ExecuteNonQuery();

                
                //SqlCommand com = new SqlCommand();
                //com.Connection = con;
                //com.CommandType = CommandType.Text;
                //com.CommandText = "select * from basicinfo";
                //SqlDataReader dr = com.ExecuteReader();//执行SQL语句
               
                //foreach (ListViewItem item in this.lv.Items)
                //{
                //    item.Remove();
                //}
                //lv.Refresh();
                //while (dr.Read())
                //{
                //    ListViewItem li = new ListViewItem(); li.SubItems.Clear();
                //    li.SubItems[0].Text = dr["id"].ToString();
                //    li.SubItems.Add(dr["name"].ToString());
                //    li.SubItems.Add(dr["sex"].ToString());
                //    li.SubItems.Add(dr["home"].ToString());
                //    li.SubItems.Add(dr["qq"].ToString());
                //    li.SubItems.Add(dr["tel"].ToString());
                //    li.SubItems.Add(dr["email"].ToString());
                //    lv.Items.Add(li);

                //}
                //dr.Close();
               
               

                con.Close();
                if (count > 0)
                {
                    MessageBox.Show("成功添加了一条记录");
                    txtID.Text = "";
                    txtName.Text = "";
                    txtSex.Text = "";
                    txtHome.Text = "";
                    txtQQ.Text = "";
                    txtTel.Text = "";
                    txtEmail.Text = "";
                }
                else
                {
                    MessageBox.Show("添加失败");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "错误");
                return;
            }
        }

查询:
 private void button1_Click(object sender, EventArgs e)
        {
            string sql = string.Format("select * from basicinfo where id='{0}'", this.txtIDBy.Text.Trim());
           
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "server=.;database=stu;Integrated Security=True";
            con.Open();
            SqlCommand sd = new SqlCommand(sql, con);
            SqlDataReader MyRead;
            MyRead = sd.ExecuteReader();
            while (MyRead.Read())
            {
                txtID.Text = MyRead[0].ToString();
                txtName.Text = MyRead[1].ToString();
                txtSex.Text = MyRead[2].ToString();
                txtHome.Text = MyRead[3].ToString();
                txtQQ.Text = MyRead[4].ToString();
                txtTel.Text = MyRead[5].ToString();
                txtEmail.Text = MyRead[6].ToString();
               
            }
            MyRead.Close();
            con.Close();
        }
删除:

 

  SqlConnection con = new SqlConnection();               
                con.ConnectionString = "server=.;database=stu;Integrated Security=True";
               
            string sql = string.Format("delete from basicinfo where id='{0}'", txtIDBy.Text ); //删除语句。
            SqlCommand cmd = new SqlCommand(sql, con);
            con.Open();
            int count = (int)cmd.ExecuteNonQuery();
           

         
            if (count > 0)
            {
                //SqlCommand com = new SqlCommand();
                //com.Connection = con;
                //com.CommandType = CommandType.Text;
                //com.CommandText = "select * from basicinfo";
                //SqlDataReader dr = com.ExecuteReader();//执行SQL语句

                //foreach (ListViewItem item in this.lv.Items)
                //{
                //    item.Remove();
                //}
                //lv.Refresh();
                //while (dr.Read())
                //{
                //    ListViewItem li = new ListViewItem(); li.SubItems.Clear();
                //    li.SubItems[0].Text = dr["id"].ToString();
                //    li.SubItems.Add(dr["name"].ToString());
                //    li.SubItems.Add(dr["sex"].ToString());
                //    li.SubItems.Add(dr["home"].ToString());
                //    li.SubItems.Add(dr["qq"].ToString());
                //    li.SubItems.Add(dr["tel"].ToString());
                //    li.SubItems.Add(dr["email"].ToString());
                //    lv.Items.Add(li);

                //}
                //dr.Close();
                MessageBox.Show("删除成功!");

            }
            else
            {
                MessageBox.Show("删除失败!");
            }
            con.Close();
        }


    C#精品课程
    http://jpkc.xmist.edu.cn/software/Csharp/default.asp