美好的一天,我找到了一些与我想要的相近的例子,例如Execute a SQL Stored Procedure and process the results但是我只是在努力看到这棵树上的树木......
我有一个SQL数据库&其中的存储过程具有变量@ModuleName
我希望用户在文本框中键入文本并单击搜索。单击搜索时,在搜索框中键入的单词将传递到@ModuleName,即Searchtext.txt = @ModuleName
然后将其传递给StoredProcedure并用于为GridView创建名为GridView1的SQL。
我尝试了很多技巧,显然遗漏了一些东西
存储过程
ALTER PROCEDURE [dbo].[spModuleID]
@ModuleName char(50)
AS
BEGIN
select * from dbo.ModuleID where [ModuleName] = @ModuleName ORDER BY [ModuleName]
END
Gridview1像这样链接到SQL ..
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True"
DataKeyNames="ModuleID">
<Columns>
<asp:BoundField DataField="ModuleID" HeaderText="ModuleID" ReadOnly="True"
SortExpression="ModuleID" />
<asp:BoundField DataField="ModuleName" HeaderText="ModuleName"
SortExpression="ModuleName" />
</Columns>
</asp:GridView>
我现在在searhc按钮下面有一些代码,希望有正确的方向......
Protected Sub Search(sender As Object, e As System.EventArgs) Handles btnSearch.Click
Dim myds As New DataSet1
MyConnection.ConnectionString = LearnConnectionString
Dim disp As New SqlDataAdapter("spModuleName", MyConnection)
disp.Fill(myds, "dev_display")
'Below wants to be a datagrid
txtDisplay.Text = myds.Tables("dev_display").Rows(0).Item("knownsoft")
myds.Dispose()
End Sub
答案 0 :(得分:0)
Imports System.Data.OleDb
Dim cmd as new Oledb.OleDbCommand
Dim connection As New SqlConnection("Connection String")
cmd.Connection = connection
cmd.CommandText = "SP_NAME"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@PARAMETER_NAME", "PARAMETER_VALUE")
Dim adapter As New SqlDataAdapter(CMD)
Dim DS as DataSet
adapter.Fill(DS)
connection.Close()
ds.Dispose()
ds = Nothing