How to write the Stored Procedure
I am having one situation,
Book Number | Book Authors | Publications | Versions
Controls i used in above fields, label in Book No., Combo box in Book Authors, Label in Publications and Combo box in Versions.
The above is my UI, if i choose the book authors from the combo box(values in combo box are retrieving from db), the values of publications and versions should retrieve from the db开发者_如何学Go based upon the item i choose from the combo box. The page should not refresh. How to write the stored procedure for this.
It seems like you really are asking the wrong question. There are a couple good answers here for how to write a select statement (via a stored procedure, or not).
However, getting the data from the database has little to do with to putting that data into the appropriate controls on your UI, and nothing to do with making sure the page does not refresh.
If you are really interested in how to how to write a stored procedure for a simple select statement, accept @MikaelEriksson's answer, but add appropriate SET statements to minimize future upgrade issues. You will also need to modify the column and table names to reflect your actual data (of course).
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE GetBooksByAuthorID
@AuthorID int
AS
BEGIN
SELECT B.BookName,
B.BookID
FROM Books as B
WHERE B.AuthorID = @AuthorID
ORDER BY B.BookName
END
GO
If you are interested in how to bind the data to your UI, and how to do it without refreshing the UI; then you need to ask a new question about that. It should be specific to your web framework. Generally speaking, if you want web UI update without refresh, you will be using some form of AJAX.
If what you're trying to do is just cascading boxes, you write a SELECT
query that return the appropriate rows. This is not what a stored procedure does.
SELECT * FROM `books` WHERE `author_id` = [author_id]
Stored procedures are used to process data, not select it.
Check this Sites to Start of:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET
Calling Stored procedures in ADO.NET
The C# Station ADO.NET Tutorial
Regards
This is how you write a stored procedure that will fetch something for you. I have of course no idea what output you want and what parameters you need so ...
create procedure GetBooksByAuthorID
@AuthorID int
as
select B.BookName,
B.BookID
from Books as B
where B.AuthorID = @AuthorID
order by B.BookName
精彩评论