Cannot implicitly convert type 'string[]' to 'string'

Hello Everyone,

i have file name "sample.txt". it contains customer order information like order id, cust id, and the order information. the below code is in c# . it has ReadButton which reads the info from the file. now my problem is how get the string[] CustResult value to be shown in Label box.

protected void ReadButton_Click(object sender, EventArgs e)



StreamReader Sr = new StreamReader(Server.MapPath(".") + "/confirm/sample.txt");

String ReadContents = Sr.ReadToEnd();

char Delimiter = '\n';

char TabDelimiter = '\t';

string[] CustResult = new string[]{ };

int i = 0;

String[] Result = ReadContents.Split(Delimiter);foreach (string oResult in Result)


CustResult[i] = oResult.Split(TabDelimiter);




lbcontent.Text = "<li>" + CustResult.ToString();



well i am getting an error saying "Compiler Error Message: CS0029: Cannot implicitly convert type 'string[]' to 'string' and its pointing to line : CustResult[i]= oResult.Split(TabDelimiter);
.......can anyone please advice me where i am making the mistake.

Thanks a lot

1/15/2008 6:13:51 PM 93655 articles. 6 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 46

split()    returns an array of strings so you cannot set it to one value of your array

my friends call me MOI
1/15/2008 6:32:28 PM

 What exactly do you want to store in this CustResult array? You are splitting the contents and foreaching through them, and then splitting the result (returns string[]) and passing it into just string. Do you want to store each value in a different array position, if so you would need a 2d array for CustResult. Do you just want the result stored in each position in CustResult? If so there's no reason to split with the TabDelimter.

Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
1/15/2008 6:33:51 PM

well the CustResult has 32 dimensions. what i mean when i ran the debugger. its showing CustResult[0]="12346" which is order it

                                                                                                                                   CustResult[1]="cust Fname"

                                                                                                                                   CustResult[2]="Email address"

                                                                                                                                   and so on.

then i want to use these so i can generate an email that can be send to customers with their order details.

any suggestions please.

Thanks a lot


1/15/2008 7:03:12 PM

Similar Artilces:

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

Cannot convert from 'string[]' to 'string'
 string[] nId = Request[PageConstants.QueryStringNotificationInstanceId].Split('/');if(string.IsNullOrEmpty(nId) == false){code } I am getting an error: Cannot convert from 'string[]' to 'string'    How to type cast this to string type. Would appreciate and help please!! Thanks!   You really can't. Since "nId" is a string array, all you can really do is extract a single element as a string like so: string x = nId[0];Thanks, EdMicrosoft MVP - ASP/ASP.NET Thanks ecburk!I did try that earlier! string[] nId = Request[P...

Operator '==' cannot be applied to operands of type 'string[]' and 'string'
Hi, I have the following C# code and the line - " if(a == "Document Library") break; " - is giving me the error - Operator '==' cannot be applied to operands of type 'string[]' and 'string' I am not very familar with c# and would appreciate any help as to how to get around this. I have checked google but can't see anything covering this. Cheers for all help... string [] a; try { currentFolder = currentFolder.Replace("%2f","/"); currentFolder = currentFolder.Replace("%20"," "); a = curre...

Cannot implicitly convert type 'string' to 'int'
Hi, I know it is a very simple question, but unfortunately i am very new to these concepts, hence kindly help me. I am trying to add a new user into the database, hence i decided to use Textboxes inorder to add. But some of the columns such as ID is of integer datatype, while Gender is of Char datatype, DateofBirth is of DateTime type. Now how do i save a value for ID, Gender etc into the database using textboxes. I am primarily working with the UserInfo class. The Userinfo is a class object that stores the data representation of the users table in the database. ...

Cannot implicitly convert type 'string' to 'bool'
Hi! I need help with this loop, basically i have 10 textboxes and 10 requiredfieldvalidators, if the textbox is hidden then disable the requiredfiledvalidator. My textboxes are name txtEmail1 thru txtEmail10 and requiredfields are named Rf1 thru Rf10. Thanks!!!for (int i = 1; i < 11; i++) {TextBox txtEmail = new TextBox();if (txtEmail + "i" + ".Text.Visible") {Rf + "i" + ".Enabled" = true; } else {Rf + "i" + ".Enabled" = false;   } } HiThe property name "Enabled" should not be in

Cannot implicitly convert type 'int' to 'string'
Hi guys, I am new to C# and ASP.Net. I need your suggestion on an issue. After clicking the Button, I grab request.querystring value which is an e-mail address from url and also I get RadioButtonList1.Text value which comes from a survey. I want to insert those two values into database using dataset but I get the following error. CS0029 :   Cannot implicitly convert type 'int' to 'string'1 string txtMail = Convert.ToString(Request.QueryString["mail"]); 2 3 AnketSonucTableAdapter sonuc = 4 new AnketSonuc...

Cannot implicitely convert type 'string' to 'System.Web.UI.WebControls.Label'
 I'm starting to make a website for users to login. Once they login, I'm showing their profile. So I populate some asp:label controls on Page_Load. My profile page (shown after the user logs in) contains: <%@ Page Language="C#" MasterPageFile="~/site.master" CodeFile="clientProfile.aspx.cs" Inherits="clientProfile" AutoEventWireup="true" Title="Car Look - Your profile" %> <asp:Content ID="Content1" ContentPlaceHolderID="mainContent" Runat="Server"> <div> &l...

Cannot implicitly convert type 'System.Web.UI.WebControls.Label' to 'string'
I have a datagridLabel ID1 = (Label)(e.Item.FindControl("ID1")); Label Name1 = (Label)(e.Item.FindControl("Name1")); Label TableName = (Label)(e.Item.FindControl("TableName"));   No0w Iam trying to TBTableName.Text = lblTableName;                  tbid.Text = lblImageTypeID1;                   tbnameordes.Text = lblImageName1; I have tried l lbltablename.text,.tostring,convert.t...

System.Net.Mail is giving error CS0029: Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress'
I'm getting an error while trying to use the wizard to create a form and than pass it the vaibles to Mail. Any help would be much appreciated. SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try {   message.From = txtEmail.Text; message.To.Add(""); message.Subject = "Feedback"; message.CC.Add(""); message.CC.Add(""); message.IsBodyHtml = false; message.Body = txtMessage.Text; smtpClient.Send(message); lblStatus.Text = "Email successfully sent."; } catch (Exception ex) { lbl...

Cannot implicitly convert type 'System.Web.UI.WebControls.Label' to 'string' #2
Hi i am getting the following error "Cannot implicitly convert type 'System.Web.UI.WebControls.Label' to 'string'", what am i doing wrong, my code looks like this;protected void lbtnSubmit_Click(object sender, EventArgs e) {foreach(DataGridItem dgi in dgAvailability.Items) {AvailabilityBLC availabilityBLC = new AvailabilityBLC(); availabilityBLC.Availability.AvailabilityDay =(Label)dgi.FindControl("lblDay");availabilityBLC.Availability.AvailabilityPrice = (TextBox)dgi.FindControl("priceTxt"); availabilityBLC.Availability.BBooked = (CheckB...

CS0029: Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.DropDownList'
I've got another error. Don't know where this is coming from. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0029: Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.DropDownList'Source Error: Line 1: <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="

CS0029: Cannot implicitly convert type 'string' to 'int'
Hi, I'm having a problem to something that should be relatively simple and I'm becoming a bit frustrated. I'm trying to write out available image sizes depending on whether the image is square or rectangular. My code goes like this: .. .. .. int imgSquare; string imgSmall, imgMed, imgLrg, imgXlrg; .. .. .. if(imgSquare == 1) { imgSmall = "5\" x 5\""; imgMed = "10\" x 10\""; imgLrg = "14 x 14"; imgXLrg = "20 x 20"; } else { imgSmall ...

Cannot implicitly convert type 'string' to 'System.DateTime'
Hi, I have a DateTime field in my sql server database. The field can take null value. In my aspx page, i have a textbox to get the input from the user. If the textbox value is empty, how to handle it? This is my cs code: objMyTime.StartTime = DateTime.Parse(txtStartTime.Text);   I am getting error as: "Cannot implicitly convert type 'string' to 'System.DateTime' " Thank you  seems to me objMyTime.StartTime is a string and ur trying to assign the datetime.try with this objMyTime.StartTime = DateTime.Parse(txtStartTime.Text).ToString();use RequiredFi...

CS0029: Cannot implicitly convert type 'string' to 'bool'
Hi, I'm having a bit of trouble with the if statement here. Basically I've got user textbox input  to look for  items that come under my music category, but if they don't add anything to the textbox then all records in every category are returned (I also have movies etc). This obviously is undesirable, so I'm trying to get the if statement to return all the records only from the music category should the user choose to click the button without entering anything. The problem I'm getting is "CS0029: Cannot implicitly convert type 'string' ...

Web resources about - Cannot implicitly convert type 'string[]' to 'string' -

Resources last updated: 1/20/2016 5:12:00 PM