|
Hi friends,
I am using Asp.Net 2.0 application. I need to convert all country time zone to my country zone. I used java script. But i got so many problems. Using web service Is it possible? If it is possible, how will do that? Give some idea to me. Or if you know any useful link for this one.
Hope your's reply.
Thanks & Regards
Every Successful Person Have A Painful Story
|
|
|
|
|
Conversion is easy. Trivial. Knowing what country people are in, is not so easy. You can assume their local clock is right, and just write the time into a hidden field, parse it, and work it out from there. I don't see how a web service would help, how could it ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
HI all,
i have to generate random password for user and hash of that password will be stored in database.
Here i want to know which approch is best for generating random password.
iam using following in function
String strString = System.Guid.NewGuid().tostring();
strString = strString.Replace("-",string.Empty);
strString = strString.Substring(0,8);
iam also reffering following link
http://aspnet.4guysfromrolla.com/articles/101205-1.aspx#postadlink[^]
Is there any best approach or technique then above from security point of view please direct me in right direction .
is there any availble class in .net for generating random password?
Best Regards
Rameez
|
|
|
|
|
rameez Raja wrote: is there any availble class in .net for generating random password?
No. Best you could do is generate characters at random that are in a given range ( i.e. all letters, letters and numbers, etc ) and appending them to a string with a stringbuilder.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I am working on CMS and i have a image library and upload url but error is below when i am trying to display the image on home page.
ImageUploadPath is neither a DataColumn nor a DataRelation for table tblImages.
Kindly do replay.
Sajjad Ali Lashari
110 Solutions Pakistan
|
|
|
|
|
i think of that you can check whether the image urlpath is exist.
Road endless its long and far,I about will seek.
|
|
|
|
|
The error means you assumed that ImageUploadPath was a valid column in your table, and it's not.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I am just confused about XML and its USE in DOTNET
Send me some details or links about this to clear my confusion
|
|
|
|
|
When you say DOTNET, are you also confused about what ASP.NET is, or just what it's called ?
XML has many uses. If you can't thnk of any, perhaps you don't need it ? It's a great way of passing heirarchical data, or storing data with a fluid schema. The ASP.NET web.config file is XML, so you can't avoid using XML if you use ASP.NET.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Please kindly help me a question : How to load dropdownlist inside Datalist in edit mode (c#)? , and get Selectedvalue ?
|
|
|
|
|
To get the selected value, you need to use FindControl to find it in each row and then check it's selection.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
hello guys, I guess my topic explaings the questions that I have... how do I remove the commas after reading a CSV file into a streamreader.
I tried using string.Split(',') but I can't assign this to a string variable because this is an array i suppose.
I'm not even sure If I should even be concerned with removing the commas from the CSV file because the goal is to read all the raw data (separeted by commas into the memory) and eventually save it to a sql server database.
Can someone please shed some light over this. I'd appreciate it!
Tina
|
|
|
|
|
the Replace method is what you need.
Why would you want to remove the commas, when they tell you where the colums are ? How can you save them to a database, if you've taken the rows and turned them into one string ? The split method is probably best, you get a string array, with each element being a column.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Removing all commas in the string is easy:
str = str.Replace(",", string.Empty);
However, that is not what you want to do. You need the commas so that you know where one value ends and the next one begins.
If no values in the line contains commas, you can use the Split method to get the values:
string[] values = line.Split(',');
However, as CSV file may be more complicated than that. A value can be enclosed in quotation marks, and then it can contain commas or even line breaks. Example:
Id, Info, Date<br />
1, Some text, 2008-12-14<br />
2, "Some text,<br />
containing commas,<br />
and line breaks.", 2008-12-15<br />
3, "More text, mind you.", 2008-12-16
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thank you Christian and Guffa, I appreciate your quick response. You guys are right, replace will work just fine but I don't need to remove those commas that separate each value.
Now as Guff mentioned above, the CSV file could have various formats...well the one I'm dealing with looks something like the following:
343243,23423432,34234234,2343423,23434234, Name, Address, Phone, Security Level, Coverage, RTX, 123 main st, 600-333-1234, Medium, Full
where the first 5 numbers just needs to be ignored (unfortunately they are part of the CSV file and we can't ask them to remove these prior to the file coming into our folder) the second 5 words will actually become the columns headers in a database table, and the remaining five values are the actual data that is corresponding to each of these columns.
Now as I said I was able to write a simple console app that reads and displays all these values in the console window using streamreader...the challange would be to write all this stuff to a SQL server 2005 database. I mean how do i grab just the values that I want and dump them in the right spot in the tabele under the corresponding column.
Guys, can you help me out here. I appreciate your answers in advance
Tina
|
|
|
|
|
If you know that the values are not quoted, you can simply split each line:
string[] col = line.Split(',');
In the array you can ignore index 0 to 4 as they are the first five columns. Index 5 to 9 are the field names, and index 10 to 14 are the values. You can create an sql query from the field names like this:
string query = "insert into SomeTable (["+col[5]+"],["+col[6]+"],["+col[7]+"],["+col[8]+"],["+col[9]+"]) values (@Col,@Col2,@Col3,@Col4,@Col5)";
Create parameters with the names @Col1 to @Col5 with the values from the index 10 to 14 in the array.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for the response Guffa. Here are a few more things I should've mentioned about the data. No the values are not quoted, and secondly I have a lot of data in that file.
here's a sample again:
343243,23423432,34234234,2343423,23434234, Name, Address, Phone, Security Level, Coverage, RTX, 123 main st, 600-333-1234, Medium, Full, RTP, 456 Main st, 777-123-8900, High, Full and so forth.
where the first 5 numbers just needs to be ignored (unfortunately they are part of the CSV file and we can't ask them to remove these prior to the file coming into our folder) the second 5 words will actually become the columns headers in a database table, and the rest is the actual data that is corresponding to each of these columns and will go under separate rows.
Now as you showed me above, I see that col[5] through col[9] will work fine in order to identify the columns accurately since we have a limited number of them, and the rest of the comma separated values in the file are data values. So in other words i could pottentially have 10,000 of those data values (rows) under these column headers...which would mean I can't pass every value myself explicitly (it has to be passed automatically somehow). Can you perhaps help me with that? SHould i create a loop or something to add the values to the parameter. A sample code snippet would help tremendously!
Thank you once again.
Tina
|
|
|
|
|
Wow, who though up that twisted use of a comma separated value file? Each line should normally contain the same number of columns, and the records would be put vertically in the file, not horisontally...
Yes, you need to use a loop to get each set of values from the line:
for (int i = 10; i < col.Length; i += 5) {
' here col[i], col[i+1] ... col[i+4] contains the five values.
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hell dear and thanks for the speedy response!
I guess I can see that you are using i+=5 instead of i++ because I told you that there might be 5 column headers and then the data would be repeated after every 5 values? Is that why you have increments of 5?
Secondly, in regards to the line
Guffa wrote: here col[i], col[i+1] ... col[i+4] contains the five values
well even if we use i based syntax instead of actual numbers...we are still doing it manually...in other words I'd still have to provide values (@Col,@Col2,@Col3,@Col4,@Col5)"; myself, which incase of tens of thousands of line, may not be practical! I'm sure thats not what you are suggesting. I think I'm missing a piece here sorry Can you please elaborate where am I wrong here?
Thanks
Tina
|
|
|
|
|
Tina P wrote: I guess I can see that you are using i+=5 instead of i++ because I told you that there might be 5 column headers and then the data would be repeated after every 5 values? Is that why you have increments of 5?
Exactly.
Tina P wrote: well even if we use i based syntax instead of actual numbers...we are still doing it manually...in other words I'd still have to provide values (@Col,@Col2,@Col3,@Col4,@Col5)"; myself, which incase of tens of thousands of line, may not be practical!
The names of the parameters has nothing to do with the index of the columns where you get the values. In fact you should name the parameters something more useful, like @Name,@Address,@Phone,@SecurityLevel,@Coverage. For the @Name parameter you use the value in col[i], for the @Address parameter you use the value in col[i+1], and so on.
Create the command object and the five parameter objects outside the loop. That way you only have to assign the values to the paramters and execut the command inside the loop.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks a lot Guffa, I appreciate you explaining it to me in such a great manner
I think I'm getting it. I wrote this quickly, do you think it make sense?
SqlConnection conn = new SqlConnection("blah blah");
string query = "insert into ClientTable ([" + col[5] + "],[" + col[6] + "],[" + col[7] + "],[" + col[8] + "],[" + col[9] + "]) values (@Name,@Address,@Phone,@SecurityLevel,@Coverage)";
SqlCommand cmd = new SqlCommand(query, conn);
SqlParameter param = new SqlParameter();
param.ParameterName = "@Name";
param.ParameterName = "@Address";
param.ParameterName = "@Phone";
param.ParameterName = "@SecurityLevel";
param.ParameterName = "@Coverage";
for (int i = 10; i < col.Length; i += 5)
{
param.Value = col[i];
param.Value = col[i+1];
param.Value = col[i+2];
param.Value = col[i+3];
param.Value = col[i+4];
cmd.Parameters.Add(param);
cmd.ExecuteReader();
}
|
|
|
|
|
Yes, but you need to create five SqlParameter objects, and add them to the command outside the loop. Specify the data type and maximum size for each parameter.
You can call the Prepare method on the command after you have added the parameters, that can reduce the number of round trips to the database.
Use the ExecuteNonQuery method to execute the command when you don't want any result back.
SqlConnection conn = new SqlConnection("blah blah");
string query = "insert into ClientTable ([" + col[5] + "],[" + col[6] + "],[" + col[7] + "],[" + col[8] + "],[" + col[9] + "]) values (@Name,@Address,@Phone,@SecurityLevel,@Coverage)";
SqlCommand cmd = new SqlCommand(query, conn);
SqlParameter parameterName = new SqlParameter("@Name", SqlDbType.VarChar, 100);
SqlParameter parameterAddress = new SqlParameter("@Address", SqlDbType.VarChar, 100);
SqlParameter parameterPhone = new SqlParameter("@Phone", SqlDbType.VarChar, 50);
SqlParameter parameterSecurity = new SqlParameter("@SecurityLevel", SqlDbType.VarChar, 50);
SqlParameter parameterCoverage = new SqlParameter("@Coverage", SqlDbType.VarChar, 50);
cmd.Parameters.Add(parameterName);
cmd.Parameters.Add(parameterAddress);
cmd.Parameters.Add(parameterPhone);
cmd.Parameters.Add(parameterSecurity);
cmd.Parameters.Add(parameterCoverage);
cmd.Prepare();
for (int i = 10; i < col.Length; i += 5) {
parameterName.Value = col[i];
parameterAddress.Value = col[i+1];
parameterPhone.Value = col[i+2];
parameterSecurity.Value = col[i+3];
parameterCoverage.Value = col[i+4];
cmd.ExecuteNonQuery();
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks a lot Guffa, I did it slightly differently but same idea.
cmd.Parameters.Add("@DATE", SqlDbType.DateTime);
for (int i = 0; i < col.Length; i += 11)
{
cmd.Parameters["@DOW"].Value = col[i+1];
etc.
cmd.ExecuteNonQuery();
}
A slighly tangential question...I notice that the column name in the table in SQL server has spaces in them
lile Fuel Location, Pin Code etc. Now it looks like in C# (or even sql server if I try to do a query without
using [] square brackets around the name, it doesnt recognize it...the question is having said that do i need
these square brackets around the Values in the query and also the place where i"m setting the value of the parameter
Is this valid?
"insert into [dbo].[MyTable] ( Name,[PIN CODE],[SERVICE CENTER]) values (@Name,@[PIN CODE],@[SERVICE CENTER])
and are the following lines valid?
cmd.Parameters.Add("@[SERVICE CENTER]", SqlDbType.NVarChar, 50);
cmd.Parameters["@[Description]"].Value = col[i+2];
p.s. my concern is the use of these brackets when the actual field in a table has space in it?
Am i correct here?
Thank in advance, you have been great!
Tina
|
|
|
|
|
Tina P wrote: the question is having said that do i need
these square brackets around the Values in the query and also the place where i"m setting the value of the parameter
You can't use square brackets around parameter names, so the parameter names can not contain spaces.
Even field names without spaces in them may need square brackets around them if they are reserved keywords, like Name .
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks again Guffa, yeah i renamed them to simple one word with no spaces.
Now I'm running into a bigger issue though...i feel pretty embarassed but it is what it is, I just don't have enough experience in development.
So right now for development purposes I have modified that file i'm reading the data from so that it has same number of columns with the headers in the third line.
Evantually the file will look something like this:
Blah Blah, More blah, etc
Blah Blah, More blah, etc
Blah Blah, More blah, etc
These lines above needs to be ignored. I had to change the looping structure a little bit because it was throwing an array index out of bound exception.
Here is what i have now:
for (int i = 0; i < 11; i ++)
{
while ((line = sr.ReadLine()) != null)
{
string[] col = line.Split(',');
cmd.Parameters["@Name"].Value = col[i];
cmd.Parameters["@location"].Value = col[i + 1];
cmd.Parameters["@pincode"].Value = DateTime.Now.Date;
cmd.Parameters["@Date"].Value = col[i + 3];
.
.
.
.
cmd.Parameters["@eta"].Value = col[i + 10];
cmd.ExecuteNonQuery();
}
}
As you notice in the for loop, i had to hard code the range because col array hasn't been created at this time...this may not be a good idea moving forward!
Secondly, I'm doing single increments (i=i+1) as you can see because the data is going to be in it separate column right next to each other.
Lastly, i notice the code above seems to be ignoring the very first line in the line...what do you think is deriving that in the for loop?
What is your take on this, this seems to be inserting the values in the data base ok? But I don;t think the for and while loops logic is correct? Can you please elaborate on this?
Thank you so much.
Tina
|
|
|
|
|