不確定。如果DataGridView1綁定了一個數據表,這個Cell的數據類型應該與表中對應字段的數據類型一致,否則就與DataGridView1自己定義的這個Cell的數據類型相同。

創新互聯堅持“要么做到,要么別承諾”的工作理念,服務領域包括:網站設計、網站建設、企業官網、英文網站、手機端網站、網站推廣等服務,滿足客戶于互聯網時代的海倫網站設計、移動媒體設計的需求,幫助企業找到有效的互聯網解決方案。努力成為您成熟可靠的網絡建設合作伙伴!
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim shkcode1 As String
Dim shimei1 As String
Dim inymd1 As String
Dim sqlstr As String
' Dim dr As DataRow
shkcode1 = DataGridView1.Rows(4).Cells(0).Value
shimei1 = DataGridView1.Rows(4).Cells(1).Value
inymd1 = DataGridView1.Rows(4).Cells(2).Value
sqlstr = " insert into EA_M1施設職員(shkcode,shimei,inymd) values ('" shkcode1 "','" shimei1 "','" inymd1 "')"
Dim connection As New OracleConnection("連接字符串")
Dim cmd As New OracleCommand(sqlstr, connection)
Try
connection.Open()
Dim rows As Integer = cmd.ExecuteNonQuery()
if rows 0 then
'說明執行成功了.可以做之后的操作
end if
Catch E As System.Data.OracleClient.OracleException
connection.Close()
Throw New Exception(E.Message)
End Try
end sub
ps:建議去學學ADO.Net 不難的.
tables有兩個嗎 如果只有一個數據表的話應該是ds.Tables(0)
1月19日補充回答:
你這段代碼都沒有ds的聲明和賦值啊……
如果你想用ds的話,可以試試這樣的代碼:
Conn = New SqlConnection() '連接本地SQL Server數據庫
Conn.ConnectionString = "Data Source=(local);Initial Catalog=dat;Integrated Security=false;User ID=sa;Password="
Conn.Open()
Dim ds As New DataSet
Dim da As New SqlClient.SqlDataAdapter(("select * from tablename", Conn)
da.Fill(ds)
Dim bs As New BindingSource()
bs.DataSource = ds
DataGridView1.DataSource = bs
If ds.Tables(0).Rows.Count 0 Then
MsgBox("有記錄")
End If
Conn.Close()
當前單元格指的是 DataGridView 焦點所在的單元格,它可以通過 DataGridView 對象的 CurrentCell 屬性取得。
如果當前單元格不存在的時候,返回Nothing(C#是null)[VB.NET]
' 取得當前單元格內容
Console.WriteLine(DataGridView1.CurrentCell.Value)
' 取得當前單元格的列 Index
Console.WriteLine(DataGridView1.CurrentCell.ColumnIndex)
' 取得當前單元格的行 Index
Console.WriteLine(DataGridView1.CurrentCell.RowIndex) [C#]
// 取得當前單元格內容
Console.WriteLine(DataGridView1.CurrentCell.Value);
// 取得當前單元格的列 Index
Console.WriteLine(DataGridView1.CurrentCell.ColumnIndex);
// 取得當前單元格的行 Index
Console.WriteLine(DataGridView1.CurrentCell.RowIndex);
另外,使用 DataGridView.CurrentCellAddress 屬性(而不是直接訪問單元格)來確定單元格所在的行:DataGridView.CurrentCellAddress.Y 和列: DataGridView.CurrentCellAddress.X 。
這對于避免取消共享行的共享非常有用。
你是想獲取總行數?還是選中行和列的索引?
獲取總行數:dataGridView1.Rows.Count;
獲取當前選中行索引:int
i
=
this.dataGridView1.CurrentRow.Index;
獲取當前選中列索引:int
j
=
this.dataGridView1.CurrentCell.ColumnIndex;
datagrid不行,因為datagrid綁定數據庫,因此不能添加一個附加行。即使在SQL命令中通過union方式進行統計后顯示,但又會導致datagrid不能新增。解決辦法有2個:1、用MSFlexGrid;2、自己寫一個用戶控件,大概意思就是里面有2個datagrid,一個大的,專門顯示記錄,一個小的,不要標題行,專門顯示合計數;在里面增加寫代碼使它們水平同步滾動。
本文名稱:vb.net中rows VBNET有什么用
當前路徑:http://www.yijiale78.com/article4/hihsoe.html
成都網站建設公司_創新互聯,為您提供靜態網站、微信小程序、企業網站制作、用戶體驗、網站收錄、虛擬主機
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯