怎样使用参数
查询 如果想通过一张表的某一个字段
查询出这张表的全部信息,并用datagrid
显示出来,应该怎么做?有哪位高人能提供一段源
代码例子给偶啊(偶的抽象思维很弱,一般要看到实例才理解得比较快,呵呵) __________________________________________________________________________ “通过一张表的某一个字段
查询出这张表的全部信息”是什么意思? __________________________________________________________________________ 写个存储过程不就行了 imports system.data.
sqlclient dim cnn as new
sqlconnection dim dataset as new dataset cnn.connectionstring= "server=srvname;database=dbname;uid=sa;pwd= " cnn.open dim adapter as
sqldataadapter=new (spname,cnn) dim pr as new
sqlparameter pr.name= ''@item '' pr.dbtype=system.type.gettype( "System.string ") pr.type=input adapter.parameters.add(pr) adapter.fill(dataset) datagrid1.datasource=dataset.table(0) __________________________________________________________________________ 楼主问题更抽象哦 看不懂啊。 是用一个字段还是用多个字段? __________________________________________________________________________ 说不清,何以道明? __________________________________________________________________________ 应该就是加条件吧,条件是有一个字段限定的。 那存储过程怎么加到
代码里呢? __________________________________________________________________________ ado.net +
sql 应该就是这样的: Imports System.Data Imports System.Data.OleDb Public Class Form1 Dim conn As New OleDbConnection Dim connstr,
sql As String Dim cmd As OleDbCommand Dim da As New OleDbDataAdapter Dim tbl As New DataTable Private Sub Conn_DB() connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Application.StartupPath & "/123.mdb " conn.ConnectionString = connstr Try conn.Open() Catch ex As Exception Msg
Box(ex.Message) End Try End Sub Private Sub DoQuery() Dim In
sql As String If conn.State = ConnectionState.Closed Then Conn_DB()
sql = "select * from mydata where " In
sql = "f1 like ''% " & Text
Box1.Text & "% '' "
sql &= In
sql In
sql = "and f2 like ''% " & Text
Box2.Text & "% '' "
sql &= In
sql In
sql = "and f3 like ''% " & Text
Box3.Text & "% '' "
sql &= In
sql cmd = New OleDbCommand(
sql,conn) da.SelectCommand = cmd tbl.Clear() da.Fill(tbl) DataGridView1.DataSource = tbl End Sub Private Sub Form1_FormClosing(ByVal sender As Object,ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing conn.Close() conn.Dispose() End Sub Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load DoQuery() End Sub Private Sub Text
Box1_KeyPress(ByVal sender As Object,ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Text
Box1.KeyPress If Convert.ToInt32(e.KeyChar) = 13 Then Text
Box2.Focus() Text
Box2.SelectAll() End If End Sub Private Sub Text
Box1_TextChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Text
Box1.TextChanged DoQuery() End Sub Private Sub Text
Box2_KeyPress(ByVal sender As Object,ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Text
Box2.KeyPress If Convert.ToInt32(e.KeyChar) = 13 Then Text
Box3.Focus() Text
Box3.SelectAll() End If End Sub Private Sub Text
Box2_TextChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Text
Box2.TextChanged DoQuery() End Sub Private Sub Text
Box3_KeyPress(ByVal sender As Object,ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Text
Box3.KeyPress If Convert.ToInt32(e.KeyChar) = 13 Then Text
Box1.Focus() Text
Box1.SelectAll() End If End Sub Private Sub Text
Box3_TextChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Text
Box3.TextChanged DoQuery() End Sub End Class 简单的做了个多字段的
查询,
显示控件使用datagridview,你看看吧 __________________________________________________________________________ 在
前台程序中,使用参数化
查询,如: strMsg = "EXEC sp_execute
sql " _ & "N''SELECT UserCode,UserName,[Password]库FROM RB_Users WHERE UserCode=@P1''," _ & "N''@P1 NVARCHAR(30)'',@P1=''" & sLoginName & "''" Con.Execute strMsg,lAffected !Con为已打开的连接,lAffected为接收受此
查询影响的行数. __________________________________________________________________________