Showing posts with label line. Show all posts
Showing posts with label line. Show all posts

Saturday, March 31, 2012

System.IndexOutOfRangeException: Index was outside the bounds of the array

Hi i am getting the following error "System.IndexOutOfRangeException: Index was outside the bounds of the array". it is coming from this line of code ;

Line 595: // Build Column Name PartLine 596: strPart1 = strPart1 + "`" + strData[lngIter, 0] + "`,";Line 597:
It may have been caused by the following code;
staticpublicstring buildQuery(string strAction,string strTableName,string[,] strData,string[,] strWhere,string strWhereOverride,string strLimit,string strOffset,string strOrderBy)

{

// Array Definitions

//strData(x,0)=ColumnName

//strData(x,1)=ColumnData

 


You will get this if you use an index that is higher than the number of items in the array. So check if the lngIter is within the index range of the array so you don't pass an index which is higher than the total amount of items in the array.


Hi, i am quite new to programming, so i am unsure if i have declared the arrays properly, however i will show you some code and if you could tell me if you can identify where i have to declare the array.;

The following code is in the page calling up a method;

clsOBJ objDHOC =newclsOBJ();

Pmillio.clsOBJ.buildQuery("INSERT","tblProperty", strData, strWhere,"","1","1","strData");

string[,] strData =newstring[11, 2];

string[,] strWhere =newstring[11, 3];

strData[0, 0] ="StatutoryDate";

strData[0, 1] = txtDate.Text;

The following code is what in the DAL which the one above is referencing;

staticpublicstring buildQuery(string strAction,string strTableName,string[,] strData,string[,] strWhere,string strWhereOverride,string strLimit,string strOffset,string strOrderBy)

{

// Array Definitions

//strData(x,0)=ColumnName

//strData(x,1)=ColumnData

// Ucase

strAction = (strAction);

// Dimension

string strSQL;

int lngIter;

string strPart1 =null;

string strPart2 =null;

Monday, March 26, 2012

System.Net.Mail & sending emails with line breaks

Hi,

When a client sends an email via a web form (text entered in a asp:TextBox server control), the email received has no line breaks, and it is displayed in one line. This has bad impact on email readability... How can one overcome this probelm?

Thank you,

Alon

If you are sending mail text in simple text format then you have to use System.Environment.NewLine to move rest text in next line.

SmtpMail.SmtpServer = "1.0.0.127";
MailMessage mm = new MailMessage();
mm.From = "bill@.microsoft.com";
mm.To = "job@.apple.com";
mm.Subject = "";
mm.Body = "line 1" + System.Environment.NewLine + "line 2";


Hi,

Thank you for your reply.

I forgot to metion that the mail is sent in HTML format:

mailMessage.IsBodyHtml =true;

Am I supposed to parse the user's message (the text in the TextBox control), chck for CRLF (or is it \n) and replace it with System.Environment.NewLine? Isn't there some standard way to send the email, as i is in the text box (multiline text box. It looks like a text area)?

Thank you,

Alon


Here is the modified code for HTML formated body

mm.Body = "line 1" + "<br>" + "line 2";

Rest of the code will remain same.


But how can I know where line1 ends and line2 starts? All I have is a string I get form TextBox.Text. From this string I cannot deduce where did the user hit return - it's a "flat" string.

A word about he context of this: this web form is a "Contact Us" page. The TextBox is a multiline text box, which serves as a free text input field.

Thank you,

Alon


As what Firoz said, you have to use the "<br />"

You will use the following code to replace each line in your textbox to break

Replace(textbox1.text, vbCrLf,"<br />")

HTH
Regards


Oooops, now I understand. It works. I thank the both of you.

Alon

Thursday, March 22, 2012

System.NullReferenceException: Object reference not set to an instance of an object.

I'm getting this error in my ASP.NET 2.0 web application when I fire following line in my code:

xmlWriter1.WriteRaw(Session["TempForm"].ToString());

Can someone tell me what am I missing ?

Does the session object TempForm exist?

I would change that code to the below and see if you still get the exception. If you do, then the issue is with xmlWriter1. If not, then it's your session variable.

string tempForm = Session["TempForm"] as string;

if (tempForm != null)
{
xmlWriter1.WriteRaw(tempForm);
}

HTH,
Ryan


Thanks Ryan, Its working now !!!

System.NullReferenceException: Object variable or With block variable not set

Please help i am getting the following error:
System.NullReferenceException: Object variable or With block variable not set

on this line.


TextBox1.Text = Trim(Row.Item("eng_lbl"))

I am trying to display the values of a record from the table in 4 text box fields.
I am new to asp.net. Please kindly help.


Dim mydataset As New DataSet
Dim myadapter As New SqlDataAdapter
Dim strId As String = Request.QueryString("lbl_Id")
Dim Row

Dim myCommand As New SqlClient.SqlCommand

Dim sql As String = "select * from tbl_labels where id =" & CInt(strId)

If Not Page.IsPostBack Then
MyCommand = New SqlCommand(sql, MyConnection)

myadapter = New SqlDataAdapter(myCommand)

mydataset.Clear()
myadapter.Fill(mydataset)

If mydataset.Tables(0).Rows.Count > 0 Then
TextBox1.Text = Trim(Row.Item("eng_lbl"))
TextBox2.Text = Trim(Row.Item("esp_lbl"))
TextBox3.Text = Trim(Row.Item("fr_lbl"))
TextBox4.Text = Trim(Row.Item("ger_lbl"))
End If
End If

You're not assign row to anything..

I.E.


Dim Row As DataRow

If mydataset.Tables(0).Rows.Count > 0 Then

Row = mydataset.Tables(0).Rows(0)

TextBox1.Text = Trim(Row.Item("eng_lbl"))

TextBox2.Text = Trim(Row.Item("esp_lbl"))

TextBox3.Text = Trim(Row.Item("fr_lbl"))

TextBox4.Text = Trim(Row.Item("ger_lbl"))

End If

Tuesday, March 13, 2012

System.Security.SecurityException: Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDEN

Hi
ACtually I am using the foolowing code
Line 22: Line 23: f3 = New Scripting.FileSystemObjectLine 24: f4 = f3.OpenTextFile(server.MapPath("visitor.txt"), 2)Line 25: f4.Write((session("hits")))Line 26: session("lock") = 1

when I was running, it is giving the following error, please help me out asap
Description:The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details:System.Security.SecurityException: Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENIED).

Thanks and Regds
Sasikumar N
Systems AnalystTry:
f4 = f3.OpenTextFile(server.MapPath("visitor.txt"), 1)
Unless you've set up some unique permissions, by default the web project runs under the ASPNET user which by default does not have write access. You are attempting to open a file in write mode...changing to 1 opens it in read mode only. Alternatively, give ASPNET user write permissions on that directory.
What trust level are you running your app in? My first instinct is that Server.MapPath isn't allowed because of your trust level. Even in medium trust you should be able to do FileIO in your own vdir. You can replace your server.MapPath call with something like:
Path.Combine( Request.PhysicalApplicationPath, "visitor.txt" )
Let me know if that solves the problem, if it's still broken, I'll help you investigate further.
--
Danny