• 大小: 308KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: C#
  • 标签: dataset  

资源简介

操作数据库,分页实例sqlserver c#

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb; // <- for database methods

namespace MovieDB
{
    public partial class Form1 : Form
    {
        public OleDbConnection database;
        DataGridViewButtonColumn editButton;
        DataGridViewButtonColumn deleteButton;
        int movieIDInt;

        #region Form1 constructor
        public Form1()
        {

            InitializeComponent();
            // iniciate DB connection
            string connectionString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=moviedb.mdb“;
            try
            {

                database = new OleDbConnection(connectionString);
                database.Open();
                //SQL query to list movies
                string queryString = “SELECT movieID title Publisher Previewed MovieYear Type FROM moviemovieType WHERE movietype.typeID = movie.typeID“;
                loadDataGrid(queryString);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
        #endregion

        #region Load dataGrid
        public void loadDataGrid(string sqlQueryString) {

            OleDbCommand SQLQuery = new OleDbCommand();
            DataTable data = null;
            dataGridView1.DataSource = null;
            SQLQuery.Connection = null;
            OleDbDataAdapter dataAdapter = null;
            dataGridView1.Columns.Clear(); // <-- clear columns
            //---------------------------------
            SQLQuery.CommandText = sqlQueryString;
            SQLQuery.Connection = database;
            data = new DataTable();
            dataAdapter = new OleDbDataAdapter(SQLQuery);
            dataAdapter.Fill(data);
            dataGridView1.DataSource = data;
            dataGridView1.AllowUserToAddRows = false; // remove the null line
            dataGridView1.ReadOnly = true;
            dataGridView1.Columns[0].Visible = false;
            dataGridView1.Columns[1].Width = 340;
            dataGridView1.Columns[3].Width = 55;
            dataGridView1.Columns[4].Width = 50;
            dataGridView1.Columns[5].Width = 80;
            // insert edit button into datagridview
            editButton = new DataGridViewButtonColumn();
            editButton.HeaderText = “Edit“;
            editButton.Text = “Edit“;
            editButton.UseColumnTextForButtonValue = true;
            editButton.Width = 80;
            dataGridView1.Columns.Add(editButton);
            // insert delete button to datagridview
            deleteButton = new DataGridViewButtonColumn();
            deleteButton.HeaderText = “Delete“;
            deleteButton.Text = “Delete“;
            deleteButton.UseColumnTextForButtonValue = true;
            deleteButton.Wid

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2008-03-28 21:37  MovieDB\
     目录           0  2008-03-01 22:24  MovieDB\MovieDB\
     目录           0  2008-03-28 21:57  MovieDB\MovieDB\MovieDB\
     目录           0  2008-03-01 22:24  MovieDB\MovieDB\MovieDB\bin\
     目录           0  2008-03-28 21:57  MovieDB\MovieDB\MovieDB\bin\Debug\
     文件        6218  2007-06-21 08:53  MovieDB\MovieDB\MovieDB\bin\Debug\Graphic1.jpg
     文件       92854  2007-01-22 15:47  MovieDB\MovieDB\MovieDB\bin\Debug\ipod_video.ico
     文件      323584  2008-03-28 21:57  MovieDB\MovieDB\MovieDB\bin\Debug\MovieDB.exe
     文件      397312  2008-03-28 21:56  MovieDB\MovieDB\MovieDB\bin\Debug\moviedb.mdb
     文件        5632  2005-09-23 05:56  MovieDB\MovieDB\MovieDB\bin\Debug\MovieDB.vshost.exe
     文件       13799  2008-03-28 21:57  MovieDB\MovieDB\MovieDB\Form1.cs
     文件       27271  2008-03-28 21:57  MovieDB\MovieDB\MovieDB\Form1.Designer.cs
     文件      155080  2008-03-28 21:57  MovieDB\MovieDB\MovieDB\Form1.resx
     文件        4177  2008-03-28 21:57  MovieDB\MovieDB\MovieDB\Form2.cs
     文件        9701  2008-03-28 21:57  MovieDB\MovieDB\MovieDB\Form2.Designer.cs
     文件      145398  2008-03-28 21:57  MovieDB\MovieDB\MovieDB\Form2.resx
     文件       92854  2007-06-21 08:56  MovieDB\MovieDB\MovieDB\ipod_video.ico
     文件        3731  2007-06-21 08:57  MovieDB\MovieDB\MovieDB\MovieDB.csproj
     文件         538  2007-06-21 08:57  MovieDB\MovieDB\MovieDB\MovieDB.csproj.user
     文件         474  2007-06-19 19:44  MovieDB\MovieDB\MovieDB\Program.cs
     目录           0  2008-03-01 22:24  MovieDB\MovieDB\MovieDB\Properties\
     文件        1262  2007-06-19 19:44  MovieDB\MovieDB\MovieDB\Properties\AssemblyInfo.cs
     文件        2841  2007-06-19 19:44  MovieDB\MovieDB\MovieDB\Properties\Resources.Designer.cs
     文件        5612  2007-06-19 19:44  MovieDB\MovieDB\MovieDB\Properties\Resources.resx
     文件        1090  2007-06-19 19:44  MovieDB\MovieDB\MovieDB\Properties\Settings.Designer.cs
     文件         249  2007-06-19 19:44  MovieDB\MovieDB\MovieDB\Properties\Settings.settings
     文件         910  2007-06-19 19:44  MovieDB\MovieDB\MovieDB.sln
     文件       18944  2008-03-28 21:57  MovieDB\MovieDB\MovieDB.suo

评论

共有 条评论