• 大小: 387KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-11
  • 语言: C#
  • 标签: vs2008  sql2005  c#  

资源简介

VS2008 C#语言访问sql2005数据库的详细例子源码。 一个小的学生管理系统。

资源截图

代码片段和文件信息

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 studentmanagement
{
    public partial class addstu : Form
    {
        DataClass DC1 = new DataClass();

        public addstu()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender EventArgs e)
        {


            if (textBox1.Text == ““ || textBox2.Text == ““ )
            {
                MessageBox.Show(“学号或姓名必须填写!“);
                return;
            }

            SqlDataReader temDR = DC1.readrow(“select * from student where sno=‘“ + textBox1.Text + “‘“);

            if (temDR == null)
            {
                DC1.execsql(“insert into student (snosnamessexbirthdate admissiondate sdeptRemarks ) values(‘“ + textBox1.Text + “‘‘“ + textBox2.Text + “‘‘“ + comboBox1.Text + “‘‘“ + dateTimePicker1.Value + “‘‘“ + dateTimePicker2.Value + “‘‘“ + comboBox2.Text + “‘‘“ + textBox3.Text + “‘)“);
                //DC1.execsql(“insert into student (snosnamessex sdeptRemarks ) values(‘“ + textBox1.Text + “‘‘“ + textBox2.Text + “‘‘“ + comboBox1.Text + “‘‘“  + comboBox2.Text + “‘‘“ + textBox3.Text + “‘)“);

            }
            else
            {
                MessageBox.Show(“学号已经被占用!“);
                return;

            }


            textBox1.Focus();
            textBox2.Text = ““;
            textBox3.Text = ““;

        }

        private void addstu_Load(object sender EventArgs e)
        {
            comboBox2.Items.Clear();
            DataTable dt = new DataTable();
            string strsql = “select sdept from dept“;
            dt = DC1.ReadTable(strsql);

            if (dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    comboBox2.Items.Add(dt.Rows[i][0].ToString());
                }
            comboBox1.SelectedIndex = 0;
            comboBox2.SelectedIndex = 0;

        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2326  2009-08-18 10:11  数据库例子\studentmanagement\addstu.cs

     文件      10535  2009-08-17 16:00  数据库例子\studentmanagement\addstu.Designer.cs

     文件       5814  2009-08-17 16:00  数据库例子\studentmanagement\addstu.resx

     文件        271  2009-08-15 16:46  数据库例子\studentmanagement\App.config

     文件    2293760  2009-09-10 15:30  数据库例子\studentmanagement\bin\Debug\mydata.mdf

     文件     573440  2009-09-10 15:30  数据库例子\studentmanagement\bin\Debug\mydata_log.ldf

     文件      29696  2009-08-25 09:22  数据库例子\studentmanagement\bin\Debug\studentmanagement.exe

     文件        271  2009-08-15 16:46  数据库例子\studentmanagement\bin\Debug\studentmanagement.exe.config

     文件      71168  2009-08-25 09:22  数据库例子\studentmanagement\bin\Debug\studentmanagement.pdb

     文件      14328  2009-09-10 15:30  数据库例子\studentmanagement\bin\Debug\studentmanagement.vshost.exe

     文件        271  2009-08-15 16:46  数据库例子\studentmanagement\bin\Debug\studentmanagement.vshost.exe.config

     文件        490  2007-07-21 01:33  数据库例子\studentmanagement\bin\Debug\studentmanagement.vshost.exe.manifest

     目录          0  2009-09-16 17:02  数据库例子\studentmanagement\bin\Debug

     目录          0  2009-09-16 17:02  数据库例子\studentmanagement\bin

     文件       3537  2009-08-18 15:07  数据库例子\studentmanagement\DataClass.cs

     文件       3129  2009-08-18 15:16  数据库例子\studentmanagement\depts.cs

     文件       7409  2009-08-17 16:24  数据库例子\studentmanagement\depts.Designer.cs

     文件       5814  2009-08-17 16:24  数据库例子\studentmanagement\depts.resx

     文件       2633  2009-08-25 09:22  数据库例子\studentmanagement\editstu.cs

     文件      10550  2009-08-25 09:22  数据库例子\studentmanagement\editstu.Designer.cs

     文件       5814  2009-08-25 09:22  数据库例子\studentmanagement\editstu.resx

     文件        367  2009-08-17 16:09  数据库例子\studentmanagement\Form1.cs

     文件       1177  2009-08-17 16:09  数据库例子\studentmanagement\Form1.Designer.cs

     文件       1322  2009-08-18 15:07  数据库例子\studentmanagement\login.cs

     文件       5061  2009-08-18 15:06  数据库例子\studentmanagement\login.Designer.cs

     文件       5814  2009-08-18 15:06  数据库例子\studentmanagement\login.resx

     文件    2293760  2009-09-10 16:30  数据库例子\studentmanagement\mydata.mdf

     文件     573440  2009-09-10 16:30  数据库例子\studentmanagement\mydata_log.LDF

     目录          0  2009-09-16 17:02  数据库例子\studentmanagement\obj\Debug\Refactor

     文件        180  2009-08-18 10:35  数据库例子\studentmanagement\obj\Debug\studentmanagement.addstu.resources

............此处省略32个文件信息

评论

共有 条评论