简体   繁体   English

从SQL数据源存储过程填充文本框

[英]Populate textboxes from SQL Datasource Stored Procedure

I have a database that has data like first name, last name, address, etc. I would like to be able to use my stored procedure I created. 我有一个数据库,其中包含诸如名,姓,地址等数据。我希望能够使用我创建的存储过程。 Here is my stored procedure. 这是我的存储过程。

ALTER PROCEDURE Edituser
@uid int
AS
Select * From Contacts
Where UserID=@uid

Now on my page in Visual Studio I create a SQLDatasource, link it to that Stored Procedure, and then how do I populate text boxes with that data that it has retrieved? 现在,在Visual Studio的页面上,我创建一个SQLDatasource,将其链接到该存储过程,然后如何用已检索到的数据填充文本框? I am not sure if I should use like the reader and do a loop maybe, im not sure so hopefully someone can help. 我不确定是否应该像读者一样使用它并做一个循环,我不确定是否希望有人可以提供帮助。

Thank You 谢谢

尝试使用DetailsViewFormView并将列绑定到适当的显示控件。

The easiest way is to click on the control you want to data bind in design view, click the arrow to expand options, and select "Choose data source..." Your SqlDataSource should show up on there, just choose it and then the fields you want to display or use. 最简单的方法是在设计视图中单击要数据绑定的控件,单击箭头以展开选项,然后选择“选择数据源...”。您的SqlDataSource应该显示在此处,只需选择它,然后选择字段您要显示或使用。 (You may need to click "Refresh schema" at the bottom). (您可能需要单击底部的“刷新架构”)。

Alternatively, you can bind controls to data sources programatically: 或者,您可以通过编程将控件绑定到数据源:

    protected void Page_Load(object sender, EventArgs e)
    {
        DropDownList1.DataSource = SqlDataSource1;
        DropDownList1.DataTextField = "foo";
        DropDownList1.DataValueField = "bar";
        DropDownList1.DataBind();
    }

Or, you can do the query manually like reggie shows if you need to manipulate or remove some data before binding it directly to a control. 或者,您可以像reggie show一样手动进行查询,以了解是否需要在直接绑定到控件之前操纵或删除一些数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM