不管怎么樣,都肯定要用到oledbCommand對吧。因為只有他能向數(shù)據(jù)庫傳達命令。
成都創(chuàng)新互聯(lián)公司專業(yè)提供成都主機托管四川主機托管成都服務器托管四川服務器托管,支持按月付款!我們的承諾:貴族品質(zhì)、平民價格,機房位于中國電信/網(wǎng)通/移動機房,雙線服務器托管服務有保障!
在程序中向oledbCommand下達命令有三種方式,其中兩個就是你說的dataset和adapter;還有一種就是:ExecuteReader;
給你一個我用的例子:
dim?conContent?as?new?system.data.oledb.oledbconnection("provider=Microsoft.jet.oledb.4.0;data?source=bbs.mdb;")
conContent.open
using??comContent?as?new?system.data.oledb.oledbcommand("SELECT?*?FROM?contenttitle?WHERE?編號='"??strNumber??"'",conContent)
with?comContent.ExecuteReader
if?.hasrows?then
.read
'?這里是一大段的操作???
end?if
end?with?
end?using
這段程序,連接了一個數(shù)據(jù)庫,然后從數(shù)據(jù)庫中取出數(shù)據(jù),然后進行操作,這段程序完了之后,comContent這個oledbCommand變量就消失了,從而不會影響再次對數(shù)據(jù)庫連接(conContent)的操作。
如果你需要寫數(shù)據(jù),那直接把SQL語句改成update就好了。
很久沒有上這里了,今天看到了這個問題,嘗試做了一個;
本例以源文本框TextBox1全部文字作為拖放文字為例,實現(xiàn)拖放
1、向一個窗體中添加兩個文本框,分別名為TextBox1,TextBox2。注意:把TextBox2控件的AllowDrop屬性設置成True,這點不要遺漏。
2、完整的代碼如下:
Public Class Form1
Private MouseIsDown As Boolean = False
Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
'設置一個標志以顯示鼠標已按下。
MouseIsDown = True
End Sub
Private Sub TextBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseMove
If MouseIsDown Then
'開始拖動(將TextBox1的文本內(nèi)容作為拖放內(nèi)容)。
TextBox1.DoDragDrop(TextBox1.Text, DragDropEffects.Copy)
End If
MouseIsDown = False
End Sub
Private Sub TextBox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragEnter
'檢查正在被拖放的數(shù)據(jù)的格式。
If (e.Data.GetDataPresent(DataFormats.Text)) Then
'顯示復制光標(表示是拖放行為)。
e.Effect = DragDropEffects.Copy
Else
'顯示不放置光標(表示不是拖放行為)。
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub TextBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragDrop
'粘貼文本(將拖放內(nèi)容作為TextBox2的文本內(nèi)容)。
TextBox2.Text = e.Data.GetData(DataFormats.Text)
End Sub
End Class
Private Declare Function GetAsyncKeyState Lib "user32" Alias "GetKeyState" (ByVal vKey As Long) As Integer
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Const VK_CONTROL = H11
Private Const SWP_NOMOVE = H2
Private Const SWP_NOSIZE = H1
Private Const HWND_TOPMOST = -1
Private Const KEYEVENTF_KEYUP = H2
Private Const WM_PASTE = H302
Private Sub Form_Load()
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
Timer1.Interval = 100
Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyControl) And H7FFF Then
On Error Resume Next
keybd_event vbKeyControl, 0, 0, 0
keybd_event vbKeyC, 0, 0, 0
keybd_event vbKeyC, 0, KEYEVENTF_KEYUP, 0
keybd_event vbKeyControl, 0, KEYEVENTF_KEYUP, 0
Text1.Text = ""
SendMessage Text1.hwnd, WM_PASTE, 0, 0
End If
End Sub
Public Declare Auto Function GetWindowText Lib "user32" Alias "GetWindowText" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Public Declare Auto Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLength" (ByVal hwnd As Integer) As Integer
Public Function GetText(ByVal hwnd As Integer) As String
Dim nLen As Integer
nLen = GetWindowTextLength(hwnd)
GetText = Space(nLen)
GetWindowText(hwnd, GetText, nLen)
End Function
VS2008測試通過, 函數(shù)GetText傳入的就是對應文本框的句柄.
非常簡單
一:如果知道要選中的行號
datagridview1.Rows(行號).Selected
=
True
datagridview1.FirstDisplayedScrollingRowIndex
=
行號
第一行是選中行號所在的行,第二行是移動滾動條將選中的行在顯示區(qū)域的最上放顯示出來。
二:根據(jù)內(nèi)容選中行并顯示
For
i
=
To
datagridview1.Rows.Count
-
1
If
datagridview1.Rows(i).Cells("列的名稱").Value
=
要選中行列的值
Then
datagridview1.Rows(i).Selected
=
True
datagridview1.FirstDisplayedScrollingRowIndex
=
i
End
If
Next
而且,如果你不想選中的行顯示到最上面,可以這樣:
For
i
=
To
datagridview1.Rows.Count
-
1
If
datagridview1.Rows(i).Cells("列的名稱").Value
=
要選中行列的值
Then
datagridview1.Rows(i).Selected
=
True
Dim
indeI
As
Integer
=
i
-
15
If
indeI
1
Then
indeI
=
1
datagridview1.FirstDisplayedScrollingRowIndex
=
indeI
End
If
Next
上面的代碼是根據(jù)某列的值選中行,并且移動滾動條將選中的行在顯示區(qū)域的第15行顯示。
請參考下面的代碼,希望能幫到你。
假設在richtextbox1中查找字符串"你是誰":
Dim start As Integer = richtextbox1.Find("你是誰", 0, RichTextBoxFinds.MatchCase)
if (start = 0) {
richtextbox1.SelectionStart = start
richtextbox1.SelectionLength = "你是誰".Length
}