把DGV數(shù)據(jù)放到datatable DataTable dt = new DataTable(); for (int j = 0; j ucgrd.Columns.Count; j++) { dt.Columns.Add(ucgrd.Columns[j].HeaderCell.Value.ToString()); } for (int j = 0; j ucgrd.Rows.Count; j++) { DataRow dr = dt...
成都創(chuàng)新互聯(lián)公司于2013年成立,先為浠水等服務建站,浠水等地企業(yè),進行企業(yè)商務咨詢服務。為浠水企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務解決您的所有建站問題。
以下是完整模塊
Imports
System.Data
Imports
System.IO
Imports
System.Data.OleDb
Module
Module1
Public
cn
As
New
OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source="
Application.StartupPath
"\mdb數(shù)據(jù)庫名字.mdb")
'定義連接
Public
DataBaseRST
As
Integer
'用來返回數(shù)據(jù)庫執(zhí)行結果
Public
Function
DataModify(ByVal
str
As
String)
As
Boolean
'進行數(shù)據(jù)庫修改操作
Dim
cmdinsert
As
New
OleDbCommand
Try
cmdinsert.CommandText
=
str
cmdinsert.Connection
=
cn
If
cn.State
=
ConnectionState.Closed
Then
cn.Open()
DataBaseRST
=
cmdinsert.ExecuteNonQuery()
'用來返回執(zhí)行的結果
cn.Close()
Return
True
Catch
ex
As
Exception
MessageBox.Show(Err.Description,
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error)
Return
False
End
Try
End
Function
Public
Function
Search(ByVal
str
As
String,
ByVal
DGV
As
DataGridView)
As
Boolean
'查詢
str---查詢命令,DGV---DataGridView,用來顯示數(shù)據(jù)的控件
Dim
tb
As
New
DataTable
Try
Dim
ap
As
New
OleDb.OleDbDataAdapter(str,
cn)
ap.Fill(tb)
DGV.DataSource
=
tb
Return
True
Catch
ex
As
Exception
MessageBox.Show(Err.Description,
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error)
Return
False
End
Try
End
Function
End
Module
'以下是調用方法
DataModify("
insert
into
aa
values
('1','2')")'-------這里是數(shù)據(jù)庫更新操作
Search("select
bb
from
aa",DataGridView1)'-----------這里是數(shù)據(jù)表查詢操作
Try
gogoodsinfo.View(" where 商品編號='" + TextBox1.Text.replace("'","''") + "'")
Catch ex As Exception
messagebox.show("錯誤信息:"+ex.tostring(),"提示")
End Try
你試一下,把我這句給復制過去看是否報錯,左邊條件要有空格,右邊要有取代函數(shù)!
select * from 表 where
(case when 條件 then 1 else 0 end+
case when 條件 then 1 else 0 end+
case when 條件 then 1 else 0 end+
case when 條件 then 1 else 0 end+
case when 條件 then 1 else 0 end) BETWEEN 2 and 5
dim
myselectquery
as
string
=
"select
*
from
表1
where
姓名='小強'"
dim
mycommand
as
new
sqlcommand
(myselectquery,
conn)
'建立一個command控件,conn是你的sqlconnection對象
conn.open()'打開數(shù)據(jù)連接
dim
myreader
as
sqldatareader'定義一個reader用來讀數(shù)據(jù)
myreader
=
mycommand.executereader()'運行你的查詢,結果到myreader
if
myreader.read()
then
'如果查到了數(shù)據(jù)
msgbox(myreader.getstring(0))
'顯示第一個字段
end
if