J
John
I just cannot manage to perform a SELECT query with NULL parameter...
My CATEGORY table does have one row where TCATEGORYPARENTID is null (real DB
null value).
TCATEGORYID and TCATEGORYPARENTID are uniqueidentifier columns.
My questions:
- is Type="Object", below, necessary?
- what shall I specify for DefaultValue in my function? I tried everything.
How come the DefaultValue must be a string? Why can't I specify
DBNull.Value?
- How do I make this work....
Thanks for your help.
-J
Code follows:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:MyBaseConnectionString %>"
SelectCommand="SELECT [TCATEGORYID], [[TCATEGORYNAME] FROM [TCATEGORY] WHERE
([TCATEGORYPARENTID] = @TCATEGORYPARENTID) ORDER BY [TCATEGORYPARENTID],
[TCATEGORYNAME]">
<SelectParameters>
<asparameter Name="TCATEGORYPARENTID" Type="Object" />
</SelectParameters>
</asp:SqlDataSource>
private void QueryCategory()
{
SqlDataSource1.SelectParameters["TCATEGORYPARENTID"].DefaultValue =
System.Data.SqlTypes.SqlGuid.Null.ToString();
DataView dv =
(DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
if (dv != null) // I always end up with either dv null or
dv.Table.Rows.Count = 0 :-(
{
string prefix = new String(' ', depth);
foreach (DataRow row in dv.Table.Rows)
{
[...]
}
}
}
My CATEGORY table does have one row where TCATEGORYPARENTID is null (real DB
null value).
TCATEGORYID and TCATEGORYPARENTID are uniqueidentifier columns.
My questions:
- is Type="Object", below, necessary?
- what shall I specify for DefaultValue in my function? I tried everything.
How come the DefaultValue must be a string? Why can't I specify
DBNull.Value?
- How do I make this work....
Thanks for your help.
-J
Code follows:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:MyBaseConnectionString %>"
SelectCommand="SELECT [TCATEGORYID], [[TCATEGORYNAME] FROM [TCATEGORY] WHERE
([TCATEGORYPARENTID] = @TCATEGORYPARENTID) ORDER BY [TCATEGORYPARENTID],
[TCATEGORYNAME]">
<SelectParameters>
<asparameter Name="TCATEGORYPARENTID" Type="Object" />
</SelectParameters>
</asp:SqlDataSource>
private void QueryCategory()
{
SqlDataSource1.SelectParameters["TCATEGORYPARENTID"].DefaultValue =
System.Data.SqlTypes.SqlGuid.Null.ToString();
DataView dv =
(DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
if (dv != null) // I always end up with either dv null or
dv.Table.Rows.Count = 0 :-(
{
string prefix = new String(' ', depth);
foreach (DataRow row in dv.Table.Rows)
{
[...]
}
}
}