Showing posts with label value. Show all posts
Showing posts with label value. Show all posts

Wednesday, March 28, 2012

Strange behaviour of Integers and Strings ?

If I am declaring a variable as integer ( int intcv_id = 0;) at the top of my page, so that i can access the value in all the methods thats my idea.

if(!IsPostBack)
{
BindData();
}

In one of my methods e.g. BindData() , I have changed the value of variable (e.g.intcv_id =Convert.ToInt32(Request.QueryString["id"]), incv_id is working properly in the BindData() method but when I am trying access the intcv_id value in some other methods, its just giving the initial value 0. I know that I can use Sessions to get over this problem, but I just want to know is there any other way out, rather than using sessions/viewstate.

Why is the integer behaving like that ? Integer is a Value-type isn't, it directly stores the value in the memory rather than its reference. Then why can't i access the stored memory value?

Its same with the strings i couldn't access the string value other than in its method , though I declare it globally. why are the value types and reference types behaving like this ?

Can anybody tell me whats happening inside please, these are basic doubts I am having though I am coding since a while

Thanks in Advance

When are you calling BindData relative to your referencing intcv_id elsewhere?

Asp.net is stateless, unless you store the value in ViewState/Session the integer variable will loose its value on postback.

I suggest create a property, each time you need the Id from the query string get it from the property.

public string Id

{

get { return Convert.ToInt32(Request.QueryString["id"]); }

}

Hope this answers your question.


Asp.net is stateless, unless you store the value in ViewState/Session the integer variable will loose its value on postback.

I suggest create a property, each time you need the Id from the query string get it from the property.

public string Id

{

get { return Convert.ToInt32(Request.QueryString["id"]); }

}

Hope this answers your question.


This is just a part of code i have edited it for readability, hope it makes sense, Thanks for your time
public partialclass viewcv : System.Web.UI.Page{SqlConnection objConn =new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["DSN"]);SqlCommand objcmd;SqlDataReader objRdr;int intcv_id = 0;string js_id ="";protected void Page_Load(object sender, System.EventArgs e){if(!IsPostBack){BindData();}}private void BindData(){if(Convert.ToString(Request.QueryString["id"])!=null){ objcmd =new SqlCommand("SelectCreateCVDetails", objConn); objcmd.CommandType = CommandType.StoredProcedure; objcmd.Parameters.Add("@.cv_id", Request.QueryString["id"]); objConn.Open(); objRdr= objcmd.ExecuteReader(); objRdr.Read(); js_id = Convert.ToString(objRdr["JS_ID"]); objRdr.Close(); intcv_id = Convert.ToInt32(Request.QueryString["id"]); }}protected void lbcv_Click(object sender, EventArgs e) { Response.Write(js_id); // here if i test its giving null which is suppose to be 29 Response.Write(intcv_id); // here its suppose to be 17 but its 0 } }
 
 

Based on this sample it appears that you need to call DataBind every time (remove the PostBack condition). The Click event can only occur during a PostBack and you're only setting the values during the initial load.

Thank you very much guys for your help.

Both the property method and by removing the !IsPostBack in the Page_Load are working great.

So, as its storing the values initially but not during the postback and as the webpages are stateless we need to store them on every Page_Load , hope I am right in my deduction.

Thank you very much guys for your help and time


There are ways to store them, but it's usually more appropriate to only load when needed and if needed on every page instantiation then in Page_Load.

Strange bug with textbox.text property

I have this is my page_load

txtSearchTerm.text = "All"

Then I have an imagebutton, when its clicked I want to redirect to a page based on the value of that textbox.

So in my imagebutton click event I have

Response.Redirect("auctions.aspx?search=" + txtSearchTerm.text)

My problem is this text is always "All", even when the user changes the value of the textbox

????

Help !

put you initialize in !IsPostBack

if(!IsPostBack){this.txtSearchTerm.Text="ALL";}

or you can set the default value in the form .aspx file use Text="ALL"


hi,

zeroxp kind of touch it a little, but i want to add something to his reply.

whenever a client click on a button on your webform, asp.net actually will reload itself, then process the Button1_Click event. Therefore, if you want to do something when the page is load, but not everytime it refrashes, use if (!IsPostBack){} or in vb.net: if page.ispostback = false then .

Just want to remind all people out there who maybe thinking this is a bug.. no it isn't... just the way asp.net webform was designed.

Alan,

Saturday, March 24, 2012

Strange error binding DataTable to DropDownList: out of range... Parameter name: value

I'm getting a nonsensical error when binding a DataTable with one row
to a DropDownList.

The DataTable's row contains the fields "id" (INT), "description"
(VARCHAR) and with a couple other unused fields.

I'm binding the table in code behind:

DataTable table=Publishinggroup.GetPublisheegroups(person.Id );
ddlPublishSource.DataSource=table;
ddlPublishSource.DataBind();

And in the aspx page, it's:

<asp:DropDownList ID="ddlPublishSource" runat="server"
DataValueField="id" DataTextField="description" /
But the error that occurs on the DataBind() command is nonsensical,
because there are no column names and no values with a value of
"value":

Specified argument was out of the range of valid values. Parameter
name: value

Any ideas on what might cause that?

Thanks,

-MikeHi-

Ok, I found the problem--the drop down list was having a value
preselected, before the datasource was assigned, but that value was no
longer in the datatable. That was why the bind was failing.

-Mike

On Wed, 07 Jul 2004 16:21:47 GMT, Mike Bridge <mike@.bridgecanada.com>
wrote:

>I'm getting a nonsensical error when binding a DataTable with one row
>to a DropDownList.

Strange Error when executing a function

in my code-behind i call a class method that returns a string value...
i run step by step and works great!!

but when i run without breakpoint... sometimes i get error because my string is empty...
and then i run again step by step... and the surprise! works fine again...

why is this happening??

this is my code-behind

string param = " ";

param +=ConfigurarLoja.RetParams( );

Session.Add("ssnHabItemVincPromo",param);

if(param == " ")

{

response.redirect("~/Erro.aspx");

}

And this is my class method:

publicstaticstring RetParams()

{

string param ="";

int cd_empresa =Convert.ToInt32(HttpContext.Current.Session["ssnCdEmpresa"]);

string sql ="SELECT TOP 1 * FROM LjConfig WHERE cd_empresa = " + cd_empresa +" AND ISNULL(DATEADD(dd, 01, dt_exclusao), GETDATE()) > GETDATE() ORDER BY dt_inclusao DESC";SqlConnection con =newSqlConnection(ConfigurationManager.ConnectionStrings["StringDeConexao"].ConnectionString);

con.Open();

SqlCommand cmd =newSqlCommand(sql, con);

SqlDataReader dr = cmd.ExecuteReader();

dr.Read();

if (dr.HasRows)

{

param ="-" + dr["cd_empresa"].ToString().Trim();

}

con.Close();

return param;

}

ops... it seems solved...
i change the sql command 'WHERE'... i think it was a problem with the GETDATE... now its working fine...

AND (ISNULL(DATEADD(dd, 01, dt_exclusao), DATEADD(dd, 01, GETDATE())) > GETDATE()) "

Thursday, March 22, 2012

Strange Issue egarding ASP:textbox control.

I have a form. I fill the text property of all the textboxes on the form to
display information to the user. If the user changes a value and clicks
save. I save the information to the database.
This sounds all well and good however the record does not get updated, in
fact I have traced it to the fact that the textbox.text property is not
being updated after the user changes the value.
Please, if you have experienced anything like this, please help. This is
very frustrating.That's not much information to go on but I suggest looking for something in
your onload that is rebinding or reloading the textbox with the original
data before you get to the click event of your save button. Remember that
onload is called before the button event.
Also, make sure you're only setting the value of the textbox from the
database when IsPostBack is false. If you're setting it in every case, you
will reset it before you get to the click event.
Good luck,
Dale
"Red" <wreyes@.optonline.net> wrote in message
news:OTvW$ONUEHA.2408@.tk2msftngp13.phx.gbl...
> I have a form. I fill the text property of all the textboxes on the form
to
> display information to the user. If the user changes a value and clicks
> save. I save the information to the database.
> This sounds all well and good however the record does not get updated, in
> fact I have traced it to the fact that the textbox.text property is not
> being updated after the user changes the value.
> Please, if you have experienced anything like this, please help. This is
> very frustrating.
>
Hey thanks alot. I can not beleive I made such a simple mistake. For days I
have been looking at everything accept for when I was displaying the data.
Anyway, thanks again.
"DalePres" <don-t-spa-m-me@.lea-ve-me-a-lone--.com> wrote in message
news:e05xBXNUEHA.2564@.TK2MSFTNGP11.phx.gbl...
> That's not much information to go on but I suggest looking for something
in
> your onload that is rebinding or reloading the textbox with the original
> data before you get to the click event of your save button. Remember that
> onload is called before the button event.
> Also, make sure you're only setting the value of the textbox from the
> database when IsPostBack is false. If you're setting it in every case,
you
> will reset it before you get to the click event.
> Good luck,
> Dale
> "Red" <wreyes@.optonline.net> wrote in message
> news:OTvW$ONUEHA.2408@.tk2msftngp13.phx.gbl...
> to
in
>

Strange Issue egarding ASP:textbox control.

I have a form. I fill the text property of all the textboxes on the form to
display information to the user. If the user changes a value and clicks
save. I save the information to the database.

This sounds all well and good however the record does not get updated, in
fact I have traced it to the fact that the textbox.text property is not
being updated after the user changes the value.

Please, if you have experienced anything like this, please help. This is
very frustrating.That's not much information to go on but I suggest looking for something in
your onload that is rebinding or reloading the textbox with the original
data before you get to the click event of your save button. Remember that
onload is called before the button event.

Also, make sure you're only setting the value of the textbox from the
database when IsPostBack is false. If you're setting it in every case, you
will reset it before you get to the click event.

Good luck,

Dale

"Red" <wreyes@.optonline.net> wrote in message
news:OTvW$ONUEHA.2408@.tk2msftngp13.phx.gbl...
> I have a form. I fill the text property of all the textboxes on the form
to
> display information to the user. If the user changes a value and clicks
> save. I save the information to the database.
> This sounds all well and good however the record does not get updated, in
> fact I have traced it to the fact that the textbox.text property is not
> being updated after the user changes the value.
> Please, if you have experienced anything like this, please help. This is
> very frustrating.
Hey thanks alot. I can not beleive I made such a simple mistake. For days I
have been looking at everything accept for when I was displaying the data.

Anyway, thanks again.

"DalePres" <don-t-spa-m-me@.lea-ve-me-a-lone--.com> wrote in message
news:e05xBXNUEHA.2564@.TK2MSFTNGP11.phx.gbl...
> That's not much information to go on but I suggest looking for something
in
> your onload that is rebinding or reloading the textbox with the original
> data before you get to the click event of your save button. Remember that
> onload is called before the button event.
> Also, make sure you're only setting the value of the textbox from the
> database when IsPostBack is false. If you're setting it in every case,
you
> will reset it before you get to the click event.
> Good luck,
> Dale
> "Red" <wreyes@.optonline.net> wrote in message
> news:OTvW$ONUEHA.2408@.tk2msftngp13.phx.gbl...
> > I have a form. I fill the text property of all the textboxes on the form
> to
> > display information to the user. If the user changes a value and clicks
> > save. I save the information to the database.
> > This sounds all well and good however the record does not get updated,
in
> > fact I have traced it to the fact that the textbox.text property is not
> > being updated after the user changes the value.
> > Please, if you have experienced anything like this, please help. This is
> > very frustrating.

Strange NULL value behaviour / RequiredFieldValidator

Hi everyone,

Im puzzled by a NULL behaviour in SQL 2000 server.

There is a column in the table that does not allow NULL.

During data mining, the staff noted that, for that particular column, there
are a few records that are empty.

I do not specifically know whether they are "alt + 0160" character.

What are the reasons that can cause this to happen?

Validation front end, I've used ASP.NET's REQUIREDFIELDVALIDATOR on the
control to ensure that the field is compulsory

On the application scripting, I've the following to cleanse the data before
the data goes into the database:

cmd.Parameters.Add("@dotnet.itags.org.STREET_NAME", Data.SqlDbType.VarChar)
cmd.Parameters("@dotnet.itags.org.STREET_NAME").Value =
ReplaceSingleQuote(streetname.Text.Trim())

The function is:

Public Shared Function ReplaceSingleQuote(ByVal x As String)

If x = "" Then
Return x
End If

x = x.Replace("'", "''")
Return x

End Function

Posted Via Usenet.com Premium Usenet Newsgroup Services
------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
------------------
http://www.usenet.comHowdy,

I see you're using Parameters so you don't need to replace any characters as
SqlParameter is responsible for that. It's only required if you build queries
through concatenation. I suspect all single quotes have been turned to doule
quotes (see it in the database). Anyway, it seems there's something wrong
with your validation as empty entries are submited.

Regards
--
Milosz

"Eric Layman" wrote:

Quote:

Originally Posted by

Hi everyone,
>
Im puzzled by a NULL behaviour in SQL 2000 server.
>
There is a column in the table that does not allow NULL.
>
During data mining, the staff noted that, for that particular column, there
are a few records that are empty.
>
I do not specifically know whether they are "alt + 0160" character.
>
What are the reasons that can cause this to happen?
>
>
Validation front end, I've used ASP.NET's REQUIREDFIELDVALIDATOR on the
control to ensure that the field is compulsory
>
On the application scripting, I've the following to cleanse the data before
the data goes into the database:
>
cmd.Parameters.Add("@.STREET_NAME", Data.SqlDbType.VarChar)
cmd.Parameters("@.STREET_NAME").Value =
ReplaceSingleQuote(streetname.Text.Trim())
>
The function is:
>
Public Shared Function ReplaceSingleQuote(ByVal x As String)
>
If x = "" Then
Return x
End If
>
x = x.Replace("'", "''")
Return x
>
End Function
>
>
>
>
>
Posted Via Usenet.com Premium Usenet Newsgroup Services
------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
------------------
http://www.usenet.com
>


Thanks for the reply.

That's very weird.

I have no idea how to account for the blank columns!

She showed me the sql commands and that column is specifically set to NOT
NULL

She asked me "How did you do that?"

"Milosz Skalecki [MCAD]" <mily242@.DONTLIKESPAMwp.plwrote in message
news:F8096D27-F0D9-430B-9166-75518B2F4F98@.microsoft.com...

Quote:

Originally Posted by

Howdy,
>
I see you're using Parameters so you don't need to replace any characters
as
SqlParameter is responsible for that. It's only required if you build
queries
through concatenation. I suspect all single quotes have been turned to
doule
quotes (see it in the database). Anyway, it seems there's something wrong
with your validation as empty entries are submited.
>
Regards
--
Milosz
>
>
"Eric Layman" wrote:
>

Quote:

Originally Posted by

>Hi everyone,
>>
>Im puzzled by a NULL behaviour in SQL 2000 server.
>>
>There is a column in the table that does not allow NULL.
>>
>During data mining, the staff noted that, for that particular column,
>there
>are a few records that are empty.
>>
>I do not specifically know whether they are "alt + 0160" character.
>>
>What are the reasons that can cause this to happen?
>>
>>
>Validation front end, I've used ASP.NET's REQUIREDFIELDVALIDATOR on the
>control to ensure that the field is compulsory
>>
>On the application scripting, I've the following to cleanse the data
>before
>the data goes into the database:
>>
>cmd.Parameters.Add("@.STREET_NAME", Data.SqlDbType.VarChar)
>cmd.Parameters("@.STREET_NAME").Value =
>ReplaceSingleQuote(streetname.Text.Trim())
>>
>The function is:
>>
> Public Shared Function ReplaceSingleQuote(ByVal x As String)
>>
> If x = "" Then
> Return x
> End If
>>
> x = x.Replace("'", "''")
> Return x
>>
> End Function
>>
>>
>>
>>
>>
> Posted Via Usenet.com Premium Usenet Newsgroup Services
>------------------
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
>------------------
> http://www.usenet.com
>>


>


Posted Via Usenet.com Premium Usenet Newsgroup Services
------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
------------------
http://www.usenet.com
Hi Eric again,

Correct me if I'm wrong but you (or she) is confusing empty string with
NULL. NULL is a special value that simply indicates nothing is assigned,
whilst empty string is a correct value. Setting NOT NULL constraint to a
varchar column means NULL value is not allowed, but any other values (like
empty string '') are. Also check if there is a default value set for this
column. Anyway, from the code you posted, I suspect, there aren't data access
layer or business logic layers as you assign values directly from user
controls. This may indicate, operations on the table are performed in several
places differently (different logic?). In addition, do you use stored
procedures or plain text queries? If SPs, please confirm there is no logic
inside that inserts empty string in some cases. And the last tip, have you
checked if there are any triggers created on this table?

Regards

--
Milosz

"Eric Layman" wrote:

Quote:

Originally Posted by

Thanks for the reply.
>
That's very weird.
>
I have no idea how to account for the blank columns!
>
She showed me the sql commands and that column is specifically set to NOT
NULL
>
She asked me "How did you do that?"
>
>
>
"Milosz Skalecki [MCAD]" <mily242@.DONTLIKESPAMwp.plwrote in message
news:F8096D27-F0D9-430B-9166-75518B2F4F98@.microsoft.com...

Quote:

Originally Posted by

Howdy,

I see you're using Parameters so you don't need to replace any characters
as
SqlParameter is responsible for that. It's only required if you build
queries
through concatenation. I suspect all single quotes have been turned to
doule
quotes (see it in the database). Anyway, it seems there's something wrong
with your validation as empty entries are submited.

Regards
--
Milosz

"Eric Layman" wrote:

Quote:

Originally Posted by

Hi everyone,
>
Im puzzled by a NULL behaviour in SQL 2000 server.
>
There is a column in the table that does not allow NULL.
>
During data mining, the staff noted that, for that particular column,
there
are a few records that are empty.
>
I do not specifically know whether they are "alt + 0160" character.
>
What are the reasons that can cause this to happen?
>
>
Validation front end, I've used ASP.NET's REQUIREDFIELDVALIDATOR on the
control to ensure that the field is compulsory
>
On the application scripting, I've the following to cleanse the data
before
the data goes into the database:
>
cmd.Parameters.Add("@.STREET_NAME", Data.SqlDbType.VarChar)
cmd.Parameters("@.STREET_NAME").Value =
ReplaceSingleQuote(streetname.Text.Trim())
>
The function is:
>
Public Shared Function ReplaceSingleQuote(ByVal x As String)
>
If x = "" Then
Return x
End If
>
x = x.Replace("'", "''")
Return x
>
End Function
>
>
>
>
>
Posted Via Usenet.com Premium Usenet Newsgroup Services
------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
------------------
http://www.usenet.com
>



>
>
>
Posted Via Usenet.com Premium Usenet Newsgroup Services
------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
------------------
http://www.usenet.com
>


Run a test to see if there are actually NULLs in that column. Run the
following query:

SELECT *
FROM MyTable
WHERE MyColumn IS NULL

If you return rows then you have some NULLs in there and we'll need to
investigate how you got NULLs into a non-nullable column. If no rows are
returned then the column does not contain NULLs, and you need to determine
how you got zero-length strings into the column if you're not expecting them
to be there. If zero-length strings are being stored but are not
acceptable, you can add a check constraint like the following to the column:

CHECK(LEN(MyColumn) 0)

"Eric Layman" <namyalcire[at no spam]gmail.comwrote in message
news:1175766804_1545@.sp6iad.superfeed.net...

Quote:

Originally Posted by

Thanks for the reply.
>
That's very weird.
>
I have no idea how to account for the blank columns!
>
She showed me the sql commands and that column is specifically set to NOT
NULL
>
She asked me "How did you do that?"
>
>
>
"Milosz Skalecki [MCAD]" <mily242@.DONTLIKESPAMwp.plwrote in message
news:F8096D27-F0D9-430B-9166-75518B2F4F98@.microsoft.com...

Quote:

Originally Posted by

>Howdy,
>>
>I see you're using Parameters so you don't need to replace any characters
>as
>SqlParameter is responsible for that. It's only required if you build
>queries
>through concatenation. I suspect all single quotes have been turned to
>doule
>quotes (see it in the database). Anyway, it seems there's something wrong
>with your validation as empty entries are submited.
>>
>Regards
>--
>Milosz
>>
>>
>"Eric Layman" wrote:
>>

Quote:

Originally Posted by

>>Hi everyone,
>>>
>>Im puzzled by a NULL behaviour in SQL 2000 server.
>>>
>>There is a column in the table that does not allow NULL.
>>>
>>During data mining, the staff noted that, for that particular column,
>>there
>>are a few records that are empty.
>>>
>>I do not specifically know whether they are "alt + 0160" character.
>>>
>>What are the reasons that can cause this to happen?
>>>
>>>
>>Validation front end, I've used ASP.NET's REQUIREDFIELDVALIDATOR on the
>>control to ensure that the field is compulsory
>>>
>>On the application scripting, I've the following to cleanse the data
>>before
>>the data goes into the database:
>>>
>>cmd.Parameters.Add("@.STREET_NAME", Data.SqlDbType.VarChar)
>>cmd.Parameters("@.STREET_NAME").Value =
>>ReplaceSingleQuote(streetname.Text.Trim())
>>>
>>The function is:
>>>
>> Public Shared Function ReplaceSingleQuote(ByVal x As String)
>>>
>> If x = "" Then
>> Return x
>> End If
>>>
>> x = x.Replace("'", "''")
>> Return x
>>>
>> End Function
>>>
>>>
>>>
>>>
>>>
>> Posted Via Usenet.com Premium Usenet Newsgroup Services
>>------------------
>> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
>>------------------
>> http://www.usenet.com
>>>


>>


>
>
>
Posted Via Usenet.com Premium Usenet Newsgroup Services
------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
------------------
http://www.usenet.com

Strange NULL value behaviour / RequiredFieldValidator

Hi everyone,
Im puzzled by a NULL behaviour in SQL 2000 server.
There is a column in the table that does not allow NULL.
During data mining, the staff noted that, for that particular column, there
are a few records that are empty.
I do not specifically know whether they are "alt + 0160" character.
What are the reasons that can cause this to happen?
Validation front end, I've used ASP.NET's REQUIREDFIELDVALIDATOR on the
control to ensure that the field is compulsory
On the application scripting, I've the following to cleanse the data before
the data goes into the database:
cmd.Parameters.Add("@dotnet.itags.org.STREET_NAME", Data.SqlDbType.VarChar)
cmd.Parameters("@dotnet.itags.org.STREET_NAME").Value =
ReplaceSingleQuote(streetname.Text.Trim())
The function is:
Public Shared Function ReplaceSingleQuote(ByVal x As String)
If x = "" Then
Return x
End If
x = x.Replace("'", "''")
Return x
End Function
Posted Via mcse.ms Premium Usenet Newsgroup Services
----
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----
http://www.mcse.msHowdy,
I see you're using Parameters so you don't need to replace any characters as
SqlParameter is responsible for that. It's only required if you build querie
s
through concatenation. I suspect all single quotes have been turned to doule
quotes (see it in the database). Anyway, it seems there's something wrong
with your validation as empty entries are submited.
Regards
--
Milosz
"Eric Layman" wrote:

> Hi everyone,
> Im puzzled by a NULL behaviour in SQL 2000 server.
> There is a column in the table that does not allow NULL.
> During data mining, the staff noted that, for that particular column, ther
e
> are a few records that are empty.
> I do not specifically know whether they are "alt + 0160" character.
> What are the reasons that can cause this to happen?
>
> Validation front end, I've used ASP.NET's REQUIREDFIELDVALIDATOR on the
> control to ensure that the field is compulsory
> On the application scripting, I've the following to cleanse the data befor
e
> the data goes into the database:
> cmd.Parameters.Add("@.STREET_NAME", Data.SqlDbType.VarChar)
> cmd.Parameters("@.STREET_NAME").Value =
> ReplaceSingleQuote(streetname.Text.Trim())
> The function is:
> Public Shared Function ReplaceSingleQuote(ByVal x As String)
> If x = "" Then
> Return x
> End If
> x = x.Replace("'", "''")
> Return x
> End Function
>
>
> Posted Via mcse.ms Premium Usenet Newsgroup Services
> ----
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----
> http://www.mcse.ms
>
Thanks for the reply.
That's very weird.
I have no idea how to account for the blank columns!
She showed me the sql commands and that column is specifically set to NOT
NULL
She asked me "How did you do that?"
"Milosz Skalecki [MCAD]" <mily242@.DONTLIKESPAMwp.pl> wrote in message
news:F8096D27-F0D9-430B-9166-75518B2F4F98@.microsoft.com...
> Howdy,
> I see you're using Parameters so you don't need to replace any characters
> as
> SqlParameter is responsible for that. It's only required if you build
> queries
> through concatenation. I suspect all single quotes have been turned to
> doule
> quotes (see it in the database). Anyway, it seems there's something wrong
> with your validation as empty entries are submited.
> Regards
> --
> Milosz
>
> "Eric Layman" wrote:
>
>
Posted Via mcse.ms Premium Usenet Newsgroup Services
----
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----
http://www.mcse.ms
Hi Eric again,
Correct me if I’m wrong but you (or she) is confusing empty string with
NULL. NULL is a special value that simply indicates nothing is assigned,
whilst empty string is a correct value. Setting NOT NULL constraint to a
varchar column means NULL value is not allowed, but any other values (like
empty string '') are. Also check if there is a default value set for this
column. Anyway, from the code you posted, I suspect, there aren’t data acc
ess
layer or business logic layers as you assign values directly from user
controls. This may indicate, operations on the table are performed in severa
l
places differently (different logic?). In addition, do you use stored
procedures or plain text queries? If SPs, please confirm there is no logic
inside that inserts empty string in some cases. And the last tip, have you
checked if there are any triggers created on this table?
Regards
Milosz
"Eric Layman" wrote:

> Thanks for the reply.
> That's very weird.
> I have no idea how to account for the blank columns!
> She showed me the sql commands and that column is specifically set to NOT
> NULL
> She asked me "How did you do that?"
>
> "Milosz Skalecki [MCAD]" <mily242@.DONTLIKESPAMwp.pl> wrote in message
> news:F8096D27-F0D9-430B-9166-75518B2F4F98@.microsoft.com...
>
> Posted Via mcse.ms Premium Usenet Newsgroup Services
> ----
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----
> http://www.mcse.ms
>
Run a test to see if there are actually NULLs in that column. Run the
following query:
SELECT *
FROM MyTable
WHERE MyColumn IS NULL
If you return rows then you have some NULLs in there and we'll need to
investigate how you got NULLs into a non-nullable column. If no rows are
returned then the column does not contain NULLs, and you need to determine
how you got zero-length strings into the column if you're not expecting them
to be there. If zero-length strings are being stored but are not
acceptable, you can add a check constraint like the following to the column:
CHECK(LEN(MyColumn) > 0)
"Eric Layman" <namyalcire[at no spam]gmail.com> wrote in message
news:1175766804_1545@.sp6iad.superfeed.net...
> Thanks for the reply.
> That's very weird.
> I have no idea how to account for the blank columns!
> She showed me the sql commands and that column is specifically set to NOT
> NULL
> She asked me "How did you do that?"
>
> "Milosz Skalecki [MCAD]" <mily242@.DONTLIKESPAMwp.pl> wrote in message
> news:F8096D27-F0D9-430B-9166-75518B2F4F98@.microsoft.com...
>
> Posted Via mcse.ms Premium Usenet Newsgroup Services
> ----
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----
> http://www.mcse.ms

Tuesday, March 13, 2012

Strange Problem

foreach(XmlNode xn in N)
{
config.AddModule(TabID, Convert.ToInt32(xn.Attributes["ModuleOrder"].Value),xn.Attributes["PaneName"].Value, xn.Attributes["ModuleTitle"].Value, Convert.ToInt32(xn.Attributes["ModuleDefId"].Value), Convert.ToInt32(xn.Attributes["CacheTimeout"].Value), xn.Attributes["EditRoles"].Value);
}

Sometimes this function executes well and stores all the values in the xmlfiles. But sometimes, it writes only half the value and disconnects. What to do?

Raja PandianCould you elaborate a little bit on your application?
I am calling a fuction inside a for loop. The function somewhat a big one which stores data to XML file. Sometimes, the function executes correct and gives me the desiered output. But manytimes I can see only half of the function executed.

Any help plz

Raja Pandian
What happens when the function doesn't execute properly? Does it throw an exception, or does it just silently miss out a whole lot of data? I see you're making some assumptions about the structure of the XML file you're reading -- e.g. ModuleOrder, ModuleDefID and CacheTimeout are integers -- if this isn't the case you may be getting NullReferenceExceptions or FormatExceptions.

If it's just silently discarding data the problem is more likely to be in your config.AddModule() method -- try stepping through it in the debugger to see what's going on.