ADO.Net中Data Table的应用

创建Data table并载入到DataGridView

SqlConnection sqlConnection = new SqlConnection();                                              
sqlConnection.ConnectionString ="Server=DESKTOP-KSC5TFT\\SQLEXPRESS;Database=OperationManagement;Integrated Security=sspi";
SqlCommand sqlCommand2 = new SqlCommand();                                                       
sqlCommand2.Connection = sqlConnection;
sqlCommand2.CommandText = "select * from operating ;";                                            
SqlDataAdapter sqlDataAdapter2 = new SqlDataAdapter();                                           
sqlDataAdapter2.SelectCommand = sqlCommand2;                                                      
sqlDataAdapter2.MissingSchemaAction = MissingSchemaAction.AddWithKey;                            
this.opname = new DataTable();
sqlConnection.Open();
sqlDataAdapter2.Fill(this.opname);
sqlConnection.Close();
this.dgv_opname.DataSource = this.opname;
this.dgv_opname.Columns["OPNo"].HeaderText = "编号";
this.dgv_opname.Columns["OPName"].HeaderText = "手术名称";
this.dgv_opname.Columns["OPcost"].HeaderText = "手术费用";
this.dgv_opname.Columns["OPtype"].HeaderText = "手术类型";
this.dgv_opname.Columns["pinyin"].Visible = false;

效果截图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值