扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
CREATE PROCEDURE Employess_Sel @lastname nvarchar (20) AS select lastname from Employees where lastname like '%' + @lastname + '%' GO |
Imports System.Data.SqlClient Public Class Class1 Dim scon As New SqlConnection("server=localhost;database=northwind;uid=sa;pwd=123") '创建一个进行查询的过程 Public Function Emp_Sel(ByVal lastname As String) As DataSet scon.Open() scon.Close() '定义命令对象,并使用储存过程 Dim scom As New SqlCommand scom.CommandType = CommandType.StoredProcedure scom.CommandText = "Employess_Sel" scom.Connection = scon '定义一个数据适配器,并设置参数 Dim sda As New SqlDataAdapter(scom) sda.SelectCommand.Parameters.Add("@lastname", SqlDbType.NVarChar).Value = lastname '定义一个数据集对象,并填充数据集 Dim ds As New DataSet Try sda.Fill(ds) Catch ex As Exception End Try Return ds End Function End Class |
Public Class WebForm1 Inherits System.Web.UI.Page '窗体代码略 '搜索按钮事件 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '定义变量储存文本框的输入,出于安全的目的对其进行转换 Dim lastname As String = TextBox1.Text lastname = lastname.Replace("&", "&") lastname = lastname.Replace("<", "") lastname = lastname.Replace(">", "") lastname = lastname.Replace("'", "’") lastname = lastname.Replace("chr(13)", "<br>") lastname = lastname.Replace("chr(10)", "<br>") '创建一个新的类实例,并调用查询过程绑定数据 Dim myCla As New ClaSql.Class1 DataGrid1.DataSource = myCla.Emp_Sel(lastname) DataGrid1.DataBind() End Sub End Class |
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=373192
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者