コード例 #1
0
        private void addScoreForm_Load_1(object sender, EventArgs e)
        {
            comboBoxCourse.DataSource    = course.getAllCourse();
            comboBoxCourse.DisplayMember = "label";
            comboBoxCourse.ValueMember   = "id";

            SqlCommand command = new SqlCommand("SELECT id, fullname FROM [dbo].[student11]");

            score_dgv.DataSource       = student.getStudents(command);
            score_dgv.Columns[0].Width = 30;
            score_dgv.Columns[1].Width = 135;
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string name = search_txt.Text;

            if (search_txt.Text.Trim() == "")
            {
                MessageBox.Show("Error", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                DB         dataBase = new DB();
                SqlCommand command  = new SqlCommand(
                    "SELECT id, fullname, dob, gender, phone, address, picture FROM student11 WHERE address = @address or fullname = @address", dataBase.GetConnection);
                command.Parameters.Add("@address", SqlDbType.NVarChar).Value = search_txt.Text;

                dataBase.openConnectionState();
                StuDB     student = new StuDB();
                DataTable table   = student.getStudents(command);
                if (table.Rows.Count > 0)
                {
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    adapter.SelectCommand = command;
                    DataSet dataSet = new DataSet();
                    adapter.Fill(dataSet, "std");
                    dataBase.closeConnection();
                    listStu.RowTemplate.Height = 50;
                    DataTable table1 = dataSet.Tables["std"];
                    listStu.DataSource = table1;
                    listStu.ReadOnly   = true;
                    DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
                    imageColumn                = (DataGridViewImageColumn)listStu.Columns[6];
                    imageColumn.ImageLayout    = DataGridViewImageCellLayout.Stretch;
                    listStu.AllowUserToAddRows = false;
                }
                else
                {
                    MessageBox.Show("not found", "Find Student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }