|
I love pompous know-it-all responses that don't answer the question.
Christian, it seemed pretty obvious that the code was written for purposes of demonstrating the problem and was not supposed to be "production code". Feel free to spend as much time as you'd like refactoring it and bringing it up to your standard.
I did some additional reading, and found this very helpful knowledge base article about stabilizing culture specific behavior in asp.net apps - if anyone else has a similar question in the future..
http://support.microsoft.com/kb/326943[^]
|
|
|
|
|
Hello,
I am reading a CSV file into the memory using a streamreader object. I was wondering if there's a way to skip every other line.
ABCD........ (read it)
EFGH........ (skip it)
Here's how I'm reading the csv file:
Command.Parameters.Add("@FirstName", SqlDbType.Nvarchar);
Command.Parameters.Add("@LocationCode", SqlDbType.Float);\
Command.Parameters.Add("@Zip", SqlDbType.Float);
for (int i = 0; i < 11; i ++)
{
while ((line = sr.ReadLine()) != null)
{
string[] col = line.Split(',');
cmd.Parameters["@FirstName"].Value = col[i];
cmd.Parameters["@LocationCode"].Value = col[i + 1];
.
.
cmd.Parameters["@Zip"].Value = col[i + 10];
cmd.ExecuteNonQuery();
}
} Thanks
Tina
|
|
|
|
|
You want to execute code in this way:
ABCD........ (read it)
EFGH........ (skip it)
IJKL.........(read it)
MNOP.........(skip it)
and so on?
Do you want to execute code inside while loop in every odd case?
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Hello there, thanks for the speedy response. Sorry couldn’t write back sooner. Yes I do want to skip every other line….chances are its going to be the odd line every single time, however as I said the data is pretty out of whack, so if they decided to add another line before we receive it…it may switch to even.
Is there a way to do code it in a way to skip either one (even or odd line) depending on my data coming in?
Thanks
Tina
|
|
|
|
|
You have to read the line then skip it in code. You can't tell the streamreader to read every other line directly.
If you know it's every other line, always, then do this:
while ((line = sr.ReadLine()) != null)
{
{
if ((line = sr.ReadLine()) != null)
{
xx
If you want the odd numbered line, do the second read at the end of the block.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hello there, thanks for the speedy response. Sorry couldn’t write back sooner. Yes I do want to skip every other line….chances are its going to be the odd line every single time, however as I said the data is pretty out of whack, so if they decided to add another line before we receive it…it may switch to even.
Christian Graus wrote: If you want the odd numbered line, do the second read at the end of the block.
Could you please elaborate on the above statement Unfornunately I don't see how would it skip the line?
Is there a way to code it in a way that it'll skip either one (even or odd line) depending on my data coming in?
Thanks
Tina
|
|
|
|
|
You'd have to read the line and then parse it if you wanted to decide as you go which line to skip. It skips a line because it reads two lines, the code to read a line is repeated, and so it reads two before doing anything with the data.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Sorry once again about the delayed response to your earlier post...i was out of town Thanks once again Christian!
I guess that make sense...is this scenario capable of handling even and odd both (lines to skip)? I'm going to try it out later tonigt but just checking with you? Thanks
Tina
|
|
|
|
|
Yes, either read two lines, then parse, or read a line, parse, then read another before the loop goes back.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hello, Christian...sorry I've been a little sick lately. ANyways, i tried but it won't work quite the way you said.
I swithced to using a TextFieldParser class in Microsoft.VisualBasic.FileIO namespace.
Here's what I'm doing:
using (TextFieldParser textParser = new TextFieldParser(sFileName))
{
textParser.TextFieldType = FieldType.Delimited;
textParser.HasFieldsEnclosedInQuotes = false;
textParser.SetDelimiters(",");
while (!textParser.EndOfData)
{
Measurements myMeasure = new Measurements();
String[] currentRow = textParser.ReadFields();
myMeasure._EmplNum= double.Parse(currentRow[0]);
myMeasure.DATE = DateTime.Parse(currentRow[1]);
myMeasure.Day = Convert.ToString(currentRow[2]);
myMeasure.Process(myMeasure);
}
}
where Process is a custom method that is used to instantiate dataContext and then invoke the stored procedure (by calling its method that is generated by LINQ to SQL)
public void Process(Measurements measObj)
{
MyDataContext dataContext = new MyDataContext();
dataContext.InsertDaily(measObj.EmplNum, measObj.Date, measObj.Day);
}
In the first code block where I'm setting up the while loop, i need to set it up in such a way that it'll skip some lines (say first 100) from the CSV file (in other words a few hundred lines of data upfron is useless and needs to be discarded but it'll be part of the CSV coming in) and then when it finally find the place where the actual data begins (lets say a keyWord such as 'Target' or something along those lines, then perhaps I need to do a string.Substring and find it...then starts reading it? I'm not quite sure how to accomplish that keeping the above code in mind.
Any advice.
Thanks a lot
Tina
|
|
|
|
|
Hey I was wondering how to use windows authentication.
In IIS what do I set? Everything I have tried setting still requires a username and password when going into the page. Now in the page I have coded it to pull active directory information.
By using User.Identity.Name I was able to get the information from AD like Division, Full name, email address. But the user still needs to login to the web page. Well our users on the local network are already logged into the network.
So how do I use User.Identity.Name without them logging into the webpage? I have set Digest Windows Authentication and when tyring to view the web page it pops up asking for a username and password.
With SharePoint it gets this information without the user logging in. If the user is logged into the network it automatically gets the information through a web page.
|
|
|
|
|
Hi,
I have a Custom control derived from webcontrol. This control has an UpdatePanel as its member variable. In the constructor of the UpdatePanel I am creating the childcontrols of the UpdatePanel
this.updatePanel.ContentTemplateContainer.Controls.Add(this);
What I want to achieve here is that when I do something like control.Invalidate(), the UpdatePanel should force the control it is tied to, to rerender i.e. call the Render method of the custom control.
for some reason this is not working. Can someone please give me some pointers on what I am doing wrong.
Thanks,
Alomgir Miah
Live Life King Size
|
|
|
|
|
An update panel means you're in the right forum. Does the Invalidate method force a postback on the AJAX control ? Or are you saying you're trying to work out what method to call to force an update panel to make an AJAX call ? Just look in the javascriot, work out what the framework calls, and call it. If you wrote AJAX code yourself, you'd know what method to call.
Funny enough, someone asked the same question and got an answer, just a few posts down.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thanks for your reply.
The website I am working in refreshes every second to keep the data up to date. Clicking the control does a AJAX postback and that part is working fine. The problem is that I want to change the control settings in the server due to some server events. Now to force the control rendering independently of all the other controls Invalidate essentially call Update() on the UpdatePanel associated with the control. For some reason the Render method of the control does not get called when the Update is called on the UpdatePanel.
googling this suggests that I need to implement ITemplate, add the control to it and replace the ContentTemplate with it. But it seems this technique is not working.
I hope I am clear enough in what I am looking for.
Thanks,
Live Life King Size
|
|
|
|
|
you want the server to force a control to update ? That can't happen. AJAX doesn't mean the server can talk to the client.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Yes it can happen. If the trigger of the UpdatePanel is set to conditional then calling Update() on the UpdatePanel will do an update. Like I was mentioning that I am doing a postback every 1 second and checking for changes. This ensures the Server forcing a client update. Only if somethings happens in the server, a certain UpdatePanel gets updated.
|
|
|
|
|
Yes, you can force it to call every second, but your server can only respond to those calls, it can't make a call to a webpage. Every AJAX call can change the controls on the page, in fact, you can use js to do that any time you like.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Yes thats true.
So I think in this hussle we forgot about the original problem. How to add a control to the UpdatePanel dynamically and force the call to UpdatePanel.Update() to call Render(HtmlWriter writer) on the child controls.
Thanks
|
|
|
|
|
I'm not sure I understood the question. You're saying if you add a control dynamically, it doesn't get drawn ? Or it doesn't get redrawn ? Is the real issue that the control loses it's state when it gets added like that ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I am saying that what a control is dynamically added it gets drawn first time correctly but in the subsequent postbacks it does not get redrawn.
What I am trying to achieve here is that if in one of the postbacks(the 1 sec postbacks) if a control has to be redrawn(new HTML tags to be generated) it should be self sufficient and should not rely on the fact that it has to be placed inside some other UpdatePanel.
On the first postback everything works fine but if in a subsequent the server tries to change the state of the control ( e.g. add a div tag with some content etc) in the Render method, it does not happen.
Thanks
|
|
|
|
|
Thanks for your help.
I have resolved the issue.
|
|
|
|
|
I am using Menu control in association with MultiView/Views. When this menu item is clicked where I have the CheckBoxList - it doesn't select the CheckBoxes from the info from my database, requires a second click.
I am not calling DataBound for some other reason. If I used databound in Page_Load, it would display fine.
Any idea how I can fix it?
Thanks.
|
|
|
|
|
Found a reasonable solution. Thanks.
|
|
|
|
|
What is your solution?
ma tju
Pengaturcara Perisian
Subang Jaya,Selangor, Malaysia
Ring Master SB MVP 2008
Subang Jaya MOP (Otai)
|
|
|
|
|
1. In Page_Load (If (!Page.IsPostBack)), get the info from the database, select the CheckBoxes that matches the criteria based on that info, and DataBind().
2) In MultiView_ActiveIndexChanged event handler, get the info from the database, select the CheckBoxes that matches the criteria based on that info.
3) Use a Save button, and in the Button_Click event handler, first Delete info from the table for the ID I am working with, then Insert values for that ID and each of the CheckBoxes that are currently selected.
4) Don't try to do anything in the SelectedIndexChanged for the CheckBoxList (which is a logical thing to try), because here, you don't know which Box is clicked as the sender is the List, not any individual CheckBox. If you have any Label to display messages, you can just clear the label here.
Thats it.
Thanks.
|
|
|
|