Showing posts with label field. Show all posts
Showing posts with label field. Show all posts

Thursday, March 29, 2012

newbie: how to compare bit field from sql table to oledbdatareader?

Hi, I made a bit field off my sql table to represent true/false.
I'm having trouble to use compare the value off that table using OleDbDataReader, please help correct my code:
string connectionString = "(connect goes here)";
string sql = "SELECT isActived FROM List WHERE ID=@dotnet.itags.org.ID";
SqlConnection conn = new SqlConnection(connectionString);
SqlDataReader reader = null;
conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
cmd.Parameters.Add("@dotnet.itags.org.license", "(my id number goes here)");
reader = cmd.ExecuteReader();
(something wrong with this code:) bool temp = reader["isActived"];
(or this:) if (
reader["isActived"] == true)
reader.Close();
conn.Close();
TIA

After a call to ExecuteRead, the reader is positioned before the first row. You must call reader.Read() to position the reader on a row before you attempt to access any data.


If you only get one value back, you may try this:
bool temp = cmd.ExecuteScalar();


thanks DMW, Jimmy, looks like ExecuteScalar would help me save a couple lines of code :)

newbie: load image from db + Repeater

hey
asp.net 2.0
With the help of a Repeater control on my webpage I want to dynamically
generate a list which contains both images and text field. This data are
stored in the aspnetdb.mdf database.
I know it's possible to have the imag tag to point to a .aspx file (<img
src="getImage.aspx" /> )
This is the Page_Load event I have in my getImage.aspx file
protected void Page_Load(object sender, EventArgs e)
{
if (Profile.Picture != null)
{
Response.ContentType = Profile.PictureType;
Response.BinaryWrite(Profile.Picture);
Response.End();
}
}
The getImage.aspx file above is used another place in my project. My PROBLEM
is that I don't know how to adapt (make another version of getImage.aspx
which suit the repeater) this getImage.aspx file into the Repeater control.
More specific: in the Page_Load event of getImage.aspx you see that I'm
setting some properties of the Response object with some values of the
Profile object. But in the new getImage.aspx file (created specially for the
Repeater control) I must for each line in the Repeater control pass over the
correct ID to the Page_Load event so the getImage.aspx file knows what image
to load!
In other words how can I tell the Page_Load event what image to show. I
think about using a paramter. But my problem is that I don't know how to add
such a parameter. Maybe it could be passed in the EventArgs argument.. I'm
not sure...
Instead of sending the picture ID I could send over the bytes representing
the image. But even that, I (As Far As I Know) still have to send a paramter
to the Page_Load event
Any ideas how I should pass over such a parameter?
Jeffhello Jeff
you can track the id's and do something like getImage ( id ) in the
ItemDataBound event.
on this page is a similar example, though uses a GridView instead, but
logically it's the same
http://authors.aspalliance.com/aspx...te.aspx

Monday, March 26, 2012

newbie: load image from db + Repeater

hey

asp.net 2.0

With the help of a Repeater control on my webpage I want to dynamically
generate a list which contains both images and text field. This data are
stored in the aspnetdb.mdf database.

I know it's possible to have the imag tag to point to a .aspx file (<img
src="getImage.aspx" />)

This is the Page_Load event I have in my getImage.aspx file
protected void Page_Load(object sender, EventArgs e)
{
if (Profile.Picture != null)
{
Response.ContentType = Profile.PictureType;
Response.BinaryWrite(Profile.Picture);
Response.End();
}
}

The getImage.aspx file above is used another place in my project. My PROBLEM
is that I don't know how to adapt (make another version of getImage.aspx
which suit the repeater) this getImage.aspx file into the Repeater control.
More specific: in the Page_Load event of getImage.aspx you see that I'm
setting some properties of the Response object with some values of the
Profile object. But in the new getImage.aspx file (created specially for the
Repeater control) I must for each line in the Repeater control pass over the
correct ID to the Page_Load event so the getImage.aspx file knows what image
to load!

In other words how can I tell the Page_Load event what image to show. I
think about using a paramter. But my problem is that I don't know how to add
such a parameter. Maybe it could be passed in the EventArgs argument.. I'm
not sure...

Instead of sending the picture ID I could send over the bytes representing
the image. But even that, I (As Far As I Know) still have to send a paramter
to the Page_Load event

Any ideas how I should pass over such a parameter?

Jeffhello Jeff

you can track the id's and do something like getImage ( id ) in the
ItemDataBound event.

on this page is a similar example, though uses a GridView instead, but
logically it's the same

http://authors.aspalliance.com/aspx...inaryWrite.aspx

Saturday, March 24, 2012

Newbie: Save and display multi-value listbox... (VB.NET)

I have a list box (i.e. FieldA) that allows the user to select more than one option. When saved, this field content is inserted in a table.

My questions are:
- How do i loop through this listbox and save the data. Do i need to concatenate the selected options into a string before or during saving?
- When this saved record is retrieved from the table, do i need to do anything in order to display the options that have previously been selected and saved?
I appreciate any coding that you can provide to assist me...

Try this article, it was helpful to me when I dealt with this same issue.
http://www.developerfusion.co.uk/show/4653/

Friday, March 16, 2012

Newlines in Datagrid

I have a very simple Datagrid with one bound field. The field has
Environment.NewLines in it. When the datagrid is rendered, they don't
appear.

I have tried a few of different ways to get them to appear:

1.) Replace Environment.NewLine with <br> before saving to the
database.
2.) Replace Environment.NewLine with </br> before saving to the
database.

Neither of these work because ASP.NET just ends up printing out the
literal <br>, </br>.

Is there a way to replace the Environment.NewLines when the datagrid is
rendered? Alternatively, is there a specific value I should be saving
to get the Datagrid to properly render the <br>?Best solution for me is to create a template column
and then replace the ItemTemplate label with a multiline textbox..

We show addresses like that and it works.

HTH.

Gerhard

<chrismichaelgardner@.hotmail.com> wrote in message
news:1126037176.699190.204720@.z14g2000cwz.googlegr oups.com...
>I have a very simple Datagrid with one bound field. The field has
> Environment.NewLines in it. When the datagrid is rendered, they don't
> appear.
> I have tried a few of different ways to get them to appear:
> 1.) Replace Environment.NewLine with <br> before saving to the
> database.
> 2.) Replace Environment.NewLine with </br> before saving to the
> database.
> Neither of these work because ASP.NET just ends up printing out the
> literal <br>, </br>.
> Is there a way to replace the Environment.NewLines when the datagrid is
> rendered? Alternatively, is there a specific value I should be saving
> to get the Datagrid to properly render the <br>?

Newlines in Datagrid

I have a very simple Datagrid with one bound field. The field has
Environment.NewLines in it. When the datagrid is rendered, they don't
appear.
I have tried a few of different ways to get them to appear:
1.) Replace Environment.NewLine with <br> before saving to the
database.
2.) Replace Environment.NewLine with </br> before saving to the
database.
Neither of these work because ASP.NET just ends up printing out the
literal <br>, </br>.
Is there a way to replace the Environment.NewLines when the datagrid is
rendered? Alternatively, is there a specific value I should be saving
to get the Datagrid to properly render the <br>?Best solution for me is to create a template column
and then replace the ItemTemplate label with a multiline textbox..
We show addresses like that and it works.
HTH.
Gerhard
<chrismichaelgardner@.hotmail.com> wrote in message
news:1126037176.699190.204720@.z14g2000cwz.googlegroups.com...
>I have a very simple Datagrid with one bound field. The field has
> Environment.NewLines in it. When the datagrid is rendered, they don't
> appear.
> I have tried a few of different ways to get them to appear:
> 1.) Replace Environment.NewLine with <br> before saving to the
> database.
> 2.) Replace Environment.NewLine with </br> before saving to the
> database.
> Neither of these work because ASP.NET just ends up printing out the
> literal <br>, </br>.
> Is there a way to replace the Environment.NewLines when the datagrid is
> rendered? Alternatively, is there a specific value I should be saving
> to get the Datagrid to properly render the <br>?
>