2012年3月29日星期四

Display 1 piece of Data from a SQLDataSource

I have the following sqlDataSource. I wan't to display one piece of data, not a whole row, from it. I can find lots of information on putting it into a datagrid, but nothing on puttin one piece in a textbox. I cannot use a formview as we are embedding html in response.write and it breaks in a formview. Thanks.

<asp:SqlDataSourcerunat="server"

ID="myEmpInfo"

SelectCommand="Select di.EmpInfo,di.eth,gc.t_level

From tblEmp di

,tblMisc gc

Where di.empnum = @.empnum

and di.empnum = gc.empnum"DataSourceMode="DataReader"ConnectionString="<%$ ConnectionStrings : myConnectionString %>">

<SelectParameters>

<asp:QueryStringParameterName="empnum"QueryStringField="empnum"/>

</SelectParameters>

</asp:SqlDataSource>

Hi,

Do you want to get the value of specific row and specific column from a table? If so,you can use DataView to achieve. See the following sample:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet" ConnectionString="<%$ ConnectionStrings:TestConnectionString2%>" ></asp:SqlDataSource>
SqlDataSource1.SelectCommand ="select CategoryName from Categories";DataView dw = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
 
/// Display all the valueforeach (DataRow drin dw.Table.Rows) {foreach (DataColumn dcin dw.Table.Columns) { Response.Write(dr[dc.ToString()].ToString() +";"); } Response.Write("\r\n"); }/// You also can use /// string str = dw.Table.Rows[0][0].ToString(); /// to get the value from a specific row specific column.
Hope that helps. Thanks.

没有评论:

发表评论