用代码给DataGridView添加新行
来源:互联网 发布:linux 串口登陆 编辑:程序博客网 时间:2024/05/22 16:13
Imports System.Data.SqlClient
Public Class Form1
Dim connection As New SqlConnection( _
"Data Source=SZC002;Initial Catalog=Northwind;" & _
"Persist Security Info=True;User ID=sa")
Dim command As New SqlCommand
Dim reader As SqlDataReader
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Using connection
connection.Open()
command.CommandText = "Select top 10 CustomerId,CompanyName From Customers"
command.Connection = connection
reader = command.ExecuteReader()
While reader.Read
Dim row As New DataGridViewRow()
Dim cell As DataGridViewTextBoxCell
cell = New DataGridViewTextBoxCell
cell.Value = reader("CustomerId").ToString
row.Cells.Add(cell)
cell = New DataGridViewTextBoxCell
cell.Value = reader("CompanyName").ToString
row.Cells.Add(cell)
With DataGridView1
方式1:.Rows.Add(New String() {reader("CustomerId").ToString, reader("CompanyName").ToString})
方式2:.Rows.Add(row)
End With
End While
connection.Close()
End Using
End Sub
End Class
- 用代码给DataGridView添加新行
- C#中/winform中,给已经绑定数据的datagridview后台动态添加新行
- 给datagridview添加行数
- C# DataGridView控件 动态添加新行
- C# DataGridView控件 动态添加新行
- C# DataGridView控件 动态添加新行 .
- DataGridView控件 动态添加新行
- C# DataGridView控件 动态添加新行
- C# DataGridView控件 动态添加新行
- C# DataGridView控件 动态添加新行
- C# DataGridView控件 动态添加新行
- C# DataGridView控件动态添加新行
- 给DataGridView添加右键菜单
- 给DataGridView添加右键菜单
- C#----给DataGridView添加行号
- ●给DataGridView添加底部合计行的一种方法
- 给DataGridView添加底部合计行的一种方法
- ●给DataGridView添加底部合计行的一种方法
- 新浪换标,也许应该做点什么了
- Application Architecture Guide 2.0 学习笔记(一)前言 - Quality Attributes
- IT技术中的言情小说
- HTTP上下文_HttpContext
- 【BASH】如何防止在重定向时覆盖现有文件
- 用代码给DataGridView添加新行
- 检测各种浏览器、系统的JS代码
- JAVA完全控制Oracle中BLOB CLOB说明
- 如何构建CMDB?
- 分页:页码显示javascript
- Google App Engine Support Java™ Language
- 世界上最牛的程序员
- 40种网页常用小技巧(javascript)
- 不要让生命留下遗憾!!