登录
首页 » C#源码 » C#操作数据库显示Customers数据表第3-7条记录

C#操作数据库显示Customers数据表第3-7条记录

于 2022-03-03 发布 文件大小:39.33 kB
0 195
下载积分: 2 下载次数: 1

代码说明:

显示Customers数据表第3-7条记录,C#操作数据库显示Customers数据表第3-7条记录,其实做出来例子,才知道,很简单啊,不过需要把数据库先连接好,看如下代码:   private void button1_Click(object sender, EventArgs e)    {//显示Customers数据表第3-7条记录    SqlConnection MyConnection=new SqlConnection();    MyConnection.ConnectionString = @"Data Source =.SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True";    MyConnection.Open();    SqlCommand MyCommand =new SqlCommand("Select * From Customers ORDER BY CustomerID", MyConnection);    DataSet MySet = new DataSet();    SqlDataAdapter MyAdapter = new SqlDataAdapter(MyCommand);    MyAdapter.Fill(MySet, 2, 5, "Customers");    this.dataGridView1.DataSource=MySet.Tables["Customers"];   }

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • C# 利用数据对象修改数据
    C# 利用数据对象修改数据,就是简单的修改数据库中的数据,利用数据对象来修改。运行效果如视图所示。本示例代码 中定义了向个C#操作数据库的方法,比如:从数据库中获取指定数据记录、在窗体中显示指定数据记录等。
    2023-05-31 11:00:03下载
    积分:1
  • 程序守护(进程守护)-C#
    程序守护(进程守护)-源代码C# /*  * 由SharpDevelop创建。  * 用户: zhang  * 日期: 2017/3/18  * 时间: 21:50  * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件  */ using System; using System.Diagnostics; using System.Drawing; using System.Threading; using System.Windows.Forms; namespace CPinfoSafe { public sealed class NotificationIcon { private NotifyIcon notifyIcon; private ContextMenu notificationMenu; DialogResult dr; #region Initialize icon and menu public NotificationIcon() { notifyIcon = new NotifyIcon(); notificationMenu = new ContextMenu(InitializeMenu()); notifyIcon.DoubleClick += IconDoubleClick; System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NotificationIcon)); notifyIcon.Icon = (Icon)resources.Get
    2022-11-01 19:35:03下载
    积分:1
  • C#操作数据库显示Customers数据表第3-7条记录
    显示Customers数据表第3-7条记录,C#操作数据库显示Customers数据表第3-7条记录,其实做出来例子,才知道,很简单啊,不过需要把数据库先连接好,看如下代码:   private void button1_Click(object sender, EventArgs e)    {//显示Customers数据表第3-7条记录    SqlConnection MyConnection=new SqlConnection();    MyConnection.ConnectionString = @"Data Source =.SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True";    MyConnection.Open();    SqlCommand MyCommand =new SqlCommand("Select * From Customers ORDER BY CustomerID", MyConnection);    DataSet MySet = new DataSet();    SqlDataAdapter MyAdapter = new SqlDataAdapter(MyCommand);    MyAdapter.Fill(MySet, 2, 5, "Customers");    this.dataGridView1.DataSource=MySet.Tables["Customers"];   }
    2022-03-03 23:39:45下载
    积分:1
  • C# 通过SqlReader HasRows判断指定表中是否有数据
    本例主要是判断指定的数据库数据表中是否有数据,这里使用了通过判断HasRows的返回值来判断,若返回值为真,则有数据,反之则无数据,最后用MessageBox.Show显示判断结果,完整的过程:   //实例化SqlConnection变量conn   SqlConnection conn = new SqlConnection("server=.;database=db_14;uid=sa;pwd=");   conn.Open();//打开连接   //创建一个SqlCommand对象   SqlCommand cmd = new SqlCommand("select * from " + textBox1.Text.Trim(), conn);   //使用ExecuteReade方法创建SqlDataReader对象   SqlDataReader sdr = cmd.ExecuteReader();   sdr.Read();//调用Read方法读取SqlDataReade   if (sdr.HasRows)//使用HasRows属性判断结果中是否有数据   {    MessageBox.Show("数据表中有值");//弹出提示信息   }   else   {    MessageBox.Show("数据表中没有任何数据");   }
    2022-02-07 01:03:03下载
    积分:1
  • C#调用存储过程显示客户的订单金额
    Visual C# 通过调用存储过程显示客户的订单金额,获取客户的订单总额(获取存储过程参数的返回值):   private void button1_Click(object sender, EventArgs e)   {//获取客户的订单总额(获取存储过程参数的返回值)    DataClasses1DataContext MyDataContext = new DataClasses1DataContext();    string MyCustomer = "alfki";    decimal? MyAmount = 0;    MyDataContext.CustOrderTotal(MyCustomer, ref MyAmount);    MessageBox.Show(MyCustomer+"客户的订单金额是:"+MyAmount.ToString(),"信息提示",MessageBoxButtons.OK);   }
    2022-10-21 01:10:03下载
    积分:1
  • C# WPF演示窗体模式的切换
    C# WPF演示窗体模式的切换,可以切换到拖放模式,切换到编辑模式。编辑模式切换的例子。
    2022-05-14 05:31:05下载
    积分:1
  • C# 异步加载图像的方法附示例
    C# 异步加载图像的方法附示例源码,异步加载技术对提升软件内容加载性能很有帮助,不但可以异步加载图片,还可以用于异步加载数据库内容,只是方法不同,本例是异步加载图片,这个也是使用比较多的一种情况,希望对C#初学者有所帮助。   运行本示例exe后,选择一张图片,则会异步加载这张图像,并显示当前图像文件加载进度,如效果图所示。
    2022-06-06 15:30:23下载
    积分:1
  • NUTTX操作系统
    Nuttx 是一个实时嵌入式操作系统(Embedded RTOS),它很小巧,在微控制器环境中使用。Nuttx完全可扩展,可从从小型(8位)至中型嵌入式(32位)系统。它的设计目的还在于完全符合POSIX标准,完全实时,并完全开放。
    2022-01-24 10:11:19下载
    积分:1
  • C# 键盘Ctrl+g控制蜂鸣器播放声音
    Visual C#播放声音,运行程序后,操作键盘上的Ctrl+g组合键发出蜂鸣声...这里的拖放声音是蜂鸣声,从音箱里发出,并不是从机箱的蜂鸣器发声。实现的过程和细节代码如下:   //导入 Windows Beep() API 函数   [DllImport("kernel32.dll")]   private static extern bool Beep(int freq, int dur);   // 定义PlaySound()要使用的常数   public const int SND_FILENAME = 0x00020000;   public const int SND_ASYNC = 0x0001;   // 导入 Windows PlaySound() 函数   [DllImport("winmm.dll")]   public static extern bool PlaySound(string pszSound,    int hmod,    int fdwSound);   [STAThread]   static void Main(string[] args)   {    // 使用Ctrl+g发出蜂鸣声    Console.Write("a");    Console.WriteLine("使用Ctrl+g发出蜂鸣声...");    Console.ReadLine();    // 使用 Windows API 发出蜂鸣声    Beep(800, 200);    Console.WriteLine("使用 Windows API 发出蜂鸣声...");    Console.ReadLine();    // 播放bells.wav文件    PlaySound("bells.wav",    0,    SND_FILENAME | SND_ASYNC);    Console.WriteLine("播放bells.wav文件...");    Console.ReadLine();   }
    2022-05-23 17:14:52下载
    积分:1
  • 《Visual.C#.编程精彩百例》配套随书光盘
    《Visual.C#.编程精彩百例》配套随书光盘源码,涉及到书中方方面面的实例,包括界面设计、数据库、系统控制、基础知识、算法、多媒体播放等众多类型的源代码,是学习C#基础编程很好的实例集。
    2023-09-09 21:35:05下载
    积分:1
  • 696516资源总数
  • 106658会员总数
  • 16今日下载