protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = Connection.DBconnection();
{
SqlCommand com = new SqlCommand("sp_selectlendingstatus", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@studentid", txtstudentid.Text.Trim());
com.Parameters.AddWithValue("@bookid", txtbookid.Text.Trim());
com.Parameters.AddWithValue("@status", status.Text.Trim());
SqlDataAdapter sda = new SqlDataAdapter(com);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
}
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" EnablePersistedSelection="True" BackColor="White"
Height="240px"
Width="755px">
<Columns>
<asp:BoundField DataField="ID" HeaderText="Student_Id" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Book_id" HeaderText="Book_id" InsertVisible="False" ReadOnly="True" SortExpression="Book_id" />
<asp:BoundField DataField="Book_name" HeaderText="Book_name" SortExpression="Book_name" />
<asp:BoundField DataField="Author_name" HeaderText="Author_name" SortExpression="Author_name" />
<asp:BoundField DataField="Publisher_name" HeaderText="Publish_name" SortExpression="Publisher_name" />
<asp:BoundField DataField="Publish_date" HeaderText="Publish_date" SortExpression="Publish_date" />
<asp:BoundField DataField="status" HeaderText="Status" SortExpression="status" />
</Columns>
</asp:GridView>
SP:
ALTER PROCEDURE sp_selectlendingstatus
AS
Begin
select * from book_lending left outer join studentlibrary ON studentlibrary.Book_id=book_lending.bookid
End
我是新來的.NET ..
在頁面加載,我需要顯示gridview。
我試過以上的源代碼,但是當我運行gridview沒有顯示。
它顯示錯誤,sp_selectlendingstatus沒有參數傳遞。
所以,如果我添加參數在這樣sp_selectlendingstatus程序,
ALTER PROCEDURE sp_selectlendingstatus
(
@bookid int,
@studentid int,
@status varchar(50)
)
AS
Begin
select * from book_lending left outer join studentlibrary ON studentlibrary.Book_id=book_lending.bookid
End
,並運行在SQL Server EXEC sp_selectlendingstatus。
它顯示錯誤@studentid,@bookid沒有提供。
我可以知道我的代碼中有什麼錯誤嗎?
任何幫助將不勝感激。
感謝,
您沒有使用查詢中的任何參數,那麼爲什麼要將參數傳遞給它? –
檢查您的查詢,這是錯誤的。 – RajeeshMenoth
請你詳細說明一下嗎?謝謝 – pcs