- 1、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
Ex9-8-11 DataGridViewExample
[例9-8至11] 演示DataGridView控件的用法。
创建一个名为DataGridViewExample的Windows窗体应用程序。
将MyDatabase.mdf文件添加到当前项目中。
从[工具箱]中向设计窗体拖放一个BindingSource组件、一个BindingNavigator组件、一个DataGridView控件和若干按钮,设计如下图的界面。其中导航条上的“保存”按钮(name:toolStripSaveButton)是利用鼠标右击导航条选择[插入标准项]命令得到的,再在导航条上添加“绑定/取消绑定到数据源”按钮(name:toolStripButtonBindingDataSource)。
添加一个名为SqlClass.cs的文件。
//SqlClass.cs
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;
namespace DataGridViewExample
{
class SqlClass
{
public DataTable DataTable1 { get; set; } //表示内存中的表
//Adapters are used to exchange data between a data source and a dataset.
public SqlDataAdapter SqlDataAdapter1; //数据适配器
public string ConnectionString { get; set; }
public SqlClass(string selectSqlString)
{
ConnectionString = Properties.Settings.Default.MyDatabaseConnectionString;
try
{
SqlDataAdapter1 = new SqlDataAdapter(selectSqlString, ConnectionString);
DataTable1 = new DataTable();
//Adds a DataTable to a DataSet and configures the schema to match that in the data source.
SqlDataAdapter1.FillSchema(DataTable1, SchemaType.Source);
//Automatically generates single-table commands that are used to reconcile changes made to a DataSet with the associated SQL Server database.
SqlCommandBuilder builder = new SqlCommandBuilder(SqlDataAdapter1);
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message, 创建适配器错误);
}
}
}
}
Form1.cs
//Form1.cs
using System;
using System.Windows.Forms;
using System.Drawing;
namespace DataGridViewExample
{
public partial class Form1 : Form
{
private SqlClass SqlClass1; //表示MyTable1
private SqlClass SqlClass2; //表示MyTable2
public Form1()
{
InitializeComponent();
SqlClass1 = new SqlCl
您可能关注的文档
- ATEN_PPT_CHAP03_V12.ppt
- ATEN_PPT_chap03_v1.2.ppt
- Atrial Fibrillation and Risk of Clinical Events in Chronic Heart Failure With and Without Left Ventr.doc
- Audio and Video Capture Support.doc
- Att8_Training Material(beginner).doc
- A__student_of_african_wildlife说课课件.ppt
- B10_bedtime story_liz_embarrassing moment.ppt
- Backup_Restore_Recovery_Win2003.ppt
- BEAMS-SHEAR AND MOMENT.ppt
- Barracuda_Backup_Recovery_Solution_20121213.pptx
- Everybody moves your body.ppt
- Excellent students1.ppt
- exercise07.doc
- Exercise_and_health(运动与健康).ppt
- Experiment-based study of the relationship between newspaper.ppt
- Finite Element Analysis of Reduction Gearbox Based on SolidWorks and ANSYS.doc
- Fiorentino:Discuss new developments regarding biologics that are FDA-approved for psoriasis.ppt
- FNA New Age.ppt
- FreeNAS的安装及使用初体验教程.doc
- FORDHAM STUDENT LIFE & RECREATION COMPLEX.docx
最近下载
- 膜下滴灌技术对阿克苏花生产量的影响机制.docx VIP
- 美国临床实验室对临床质谱方法的质量管理要求.docx VIP
- 船用 6135 柴油机的维护要点.docx VIP
- GKGG5全自动印刷机操作规范标准1行业资料国内外标准规范.docx VIP
- 国标图集06J505-1 (1)-国家建筑标准设计图集电子版下载 2.pdf VIP
- 《花生膜下滴灌技术》课件.pptx VIP
- 公众号管理应急预案.docx
- 花生膜下滴灌技术.ppt VIP
- 2024年全国高中化学竞赛决赛冬令营理论试题及答案 .pdf VIP
- 2025广西公需科目考试答案(3套涵盖95-试题)一区两地一园一通道建设人工智能时代的机遇与挑战.pdf VIP
文档评论(0)