how to use left function in a selectcommand in aspx file?

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

Hi,

i tested this sql command directly with sql server and it works:
select left(field1,10) from mytable

Now, i tried the same in aspx file: i dragged a sqldatasource control and
changed manually the select commend like this:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myconn %>"
SelectCommand="SELECT left(field1,10) FROM [mytable]">
</asp:SqlDataSource>

But here, i get the error:
"no field or property met with the name field1in the selected source .."(or
something)

Any way to limit the text of field 'field1' to 10 characters?

Thanks
Eric
 
Thanks for replying, but i get the same error.

sloan said:
THrow in an alias I think
SELECT left(field1,10) as MyAlias1 FROM [mytable]



Eric said:
Hi,

i tested this sql command directly with sql server and it works:
select left(field1,10) from mytable

Now, i tried the same in aspx file: i dragged a sqldatasource control and
changed manually the select commend like this:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myconn %>"
SelectCommand="SELECT left(field1,10) FROM [mytable]">
</asp:SqlDataSource>

But here, i get the error:
"no field or property met with the name field1in the selected source
.."(or something)

Any way to limit the text of field 'field1' to 10 characters?

Thanks
Eric
 
Use storedprocedure, or get the data, then .. fix it. (Which is what the
presentation layer is supposed to do anyways).


Eric said:
Thanks for replying, but i get the same error.

sloan said:
THrow in an alias I think
SELECT left(field1,10) as MyAlias1 FROM [mytable]



Eric said:
Hi,

i tested this sql command directly with sql server and it works:
select left(field1,10) from mytable

Now, i tried the same in aspx file: i dragged a sqldatasource control
and changed manually the select commend like this:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myconn %>"
SelectCommand="SELECT left(field1,10) FROM [mytable]">
</asp:SqlDataSource>

But here, i get the error:
"no field or property met with the name field1in the selected source
.."(or something)

Any way to limit the text of field 'field1' to 10 characters?

Thanks
Eric
 
It works if i do this:
SELECT left(n1,10) as n1 (with the same fieldname in the alias.

sloan said:
Use storedprocedure, or get the data, then .. fix it. (Which is what the
presentation layer is supposed to do anyways).


Eric said:
Thanks for replying, but i get the same error.

sloan said:
THrow in an alias I think
SELECT left(field1,10) as MyAlias1 FROM [mytable]



Hi,

i tested this sql command directly with sql server and it works:
select left(field1,10) from mytable

Now, i tried the same in aspx file: i dragged a sqldatasource control
and changed manually the select commend like this:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myconn %>"
SelectCommand="SELECT left(field1,10) FROM [mytable]">
</asp:SqlDataSource>

But here, i get the error:
"no field or property met with the name field1in the selected source
.."(or something)

Any way to limit the text of field 'field1' to 10 characters?

Thanks
Eric
 
Oh, ok.

I was close....

Glad you figured it out.


Eric said:
It works if i do this:
SELECT left(n1,10) as n1 (with the same fieldname in the alias.

sloan said:
Use storedprocedure, or get the data, then .. fix it. (Which is what the
presentation layer is supposed to do anyways).


Eric said:
Thanks for replying, but i get the same error.

"sloan" <[email protected]> schreef in bericht
THrow in an alias I think
SELECT left(field1,10) as MyAlias1 FROM [mytable]



Hi,

i tested this sql command directly with sql server and it works:
select left(field1,10) from mytable

Now, i tried the same in aspx file: i dragged a sqldatasource control
and changed manually the select commend like this:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myconn %>"
SelectCommand="SELECT left(field1,10) FROM [mytable]">
</asp:SqlDataSource>

But here, i get the error:
"no field or property met with the name field1in the selected source
.."(or something)

Any way to limit the text of field 'field1' to 10 characters?

Thanks
Eric
 
Back
Top