|
I'm guessing that maybe the values are the same, but the objects are not.
I'm not sure how the == operator compares the DateTimes, but it could be that the culture eg. (or something else) is different. Maybe you can print out the values of several properties and compare them.
godd luck.
I've found a living worth working for, but I haven't found work worth living for.
<marquee>
|
|
|
|
|
As DateTime is a value type, the == operator will be comparing the values, not the objects.
The actual values that will be compared is the value of the Ticks property. A tick is 100 nanoseconds, so the values have to be exactly the same to be equal. If they are off by 0.0000001 seconds, they are not equal.
---
b { font-weight: normal; }
|
|
|
|
|
Guffa wrote: As DateTime is a value type, the == operator will be comparing the values, not the objects
you're probably right
Guffa wrote: The actual values that will be compared is the value of the Ticks property. A tick is 100 nanoseconds, so the values have to be exactly the same to be equal. If they are off by 0.0000001 seconds, they are not equal
this, I knew
tnx
I've found a living worth working for, but I haven't found work worth living for.
<marquee>
|
|
|
|
|
A. The ReportDate is passed to the select statement.
B. The select statement supposedly retrieves all rows equalling that value.
C. The select statement returns the value contained in the ReportDate AND the BalanceOH fields.
D. Irrespective of what date I pass to the select statement, it always retieves row 0, etc AND the comparative statement is only there for cosmetic and confirmation of B. not returning the correct BalanceOH figure.
E. The value of BalanceOH is not the balance corresponding to the date I want.
F. The comparison is only made to confirm to me that I don't know what I'm doing.
If there was a problem with the formatting of the dates, then I don't see why the select statement is retrieving any rows at all.
What I think is wrong is that I am always going to get the value 0 returned becuase that is what the value of i is. Shouldn't I be passing the value of the row number corresponding to the selected ReportDate of the datatable?
BalanceOH = Convert.ToDecimal(myclubDataSet.Tables["TresReports"].Rows[i]["BalanceOH"]);
Glen Harvy
|
|
|
|
|
Glen Harvy wrote: If there was a problem with the formatting of the dates, then I don't see why the select statement is retrieving any rows at all.
Actually I'm not talking about the formatting.
What I thought was that the culture retrieved from the database was eg. EN-us while the culture you are working with was Neutral. Furthermore, according to Guffa, the "==" operator should only check the values. In that case I was wrong.
How many rows do you retrieve? Isn't there a possibility to step into the code?
Also, as mentioned above by Guffa, one thick difference is a difference.
You could check eg. on year, month, and day instead of the entire DateTime object.
The problem probably lies in a very small corner.
Glen Harvy wrote: What I think is wrong is that I am always going to get the value 0 returned becuase that is what the value of i is. Shouldn't I be passing the value of the row number corresponding to the selected ReportDate of the datatable?
BalanceOH = Convert.ToDecimal(myclubDataSet.Tables["TresReports"].Rows[i]["BalanceOH"]);
I'm not sure what you mean by this, but a DataSet is just like a the view you get when executing a select statement. What you can do is execute the select statement in the database itself. That view should exactly be the contents of your DataSet. If you iterate through it with a for loop you should get each row of that view.
Good luck.
I've found a living worth working for, but I haven't found work worth living for.
<marquee>
|
|
|
|
|
If any body call URLDownloadToFile using c#.net in web application,
what are the parameters that i shall pass.
Bibhu
|
|
|
|
|
Hi. i am still new on C#.i am trying to display data on the texboxes from database using classes but it doesn't display any data where as is there here is my class.
public void SeachCustomer(string CName,string CNum)
{
CustomerName = CName;
Barcode1 = CNum;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "integrated security=SSPI;initial catalog=Phusa;server = za211149;persist security info=False";
conn.Open();
try
{
SqlCommand cmdSearch = new SqlCommand();
cmdSearch.Connection = conn;
cmdSearch.CommandText = "SELECT CustomerName FROM Events WHERE Barcode1 =@Barcode1";
SqlParameter Bar = new SqlParameter();
Bar.ParameterName = "@Barcode1";
Bar.Direction = System.Data.ParameterDirection.Output;
Bar.Value = Barcode1;
cmdSearch.Parameters.Add(Bar);
SqlParameter Nam = new SqlParameter();
Nam.ParameterName="@CustomerName";
Nam.Direction = System.Data.ParameterDirection.Output;
Nam.Value =CustomerName;
cmdSearch.Parameters.Add(Nam);
SqlDataReader dr =cmdSearch.ExecuteReader();
while(dr.Read()==true)
{
CustomerName = dr["CustomerName"].ToString();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
-- modified at 4:02 Wednesday 16th August, 2006
|
|
|
|
|
Hi,
First of all you haven't added the 'Bar' parameter.
Mamphekgo wrote: cmdSearch.Parameters.Add(Nam);
As shown above only the 'Nam' param is added.
Mamphekgo wrote: i am trying to display data on the texboxes from database
You have not written any code to display the data ?
Another problem is that CustomerName will only contain the last row's data , bcoz u r not concatenating the strings..
Mamphekgo wrote: CustomerName = dr["CustomerName"].ToString();
Try to provide complete code if you have missed something or try to correct the above said errors and check for the desired result.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
actually my code can see that there is data on the database because when i use messagebox to search if ever there is something ot the database it shows that it found the record.but data cannot display on the texboxes,here i am trying to call my class to display data.
SearchCustomers search = new SearchCustomers();
string Barcode1;
string CustomerName ="";
string Barcode;
string ProductName="";
string Price = "";
if(txtBarcode.Text.Length <4)
{
Barcode1 =txtBarcode.Text;
CustomerName = lblCustomerName.Text;
search.SeachCustomer(CustomerName,Barcode1);
}
else
{
Barcode = txtBarcode.Text;
lblProductName.Text = ProductName;
lblPrice.Text =Price.ToString();
search.SeachProduct(Barcode,ProductName,Price);
}
|
|
|
|
|
Hi,
Sorry, I didnt got you still. Since you are using the SearchCustomer function to search the db, but it dosent returns any value ?
Mamphekgo wrote: search.SeachCustomer(CustomerName,Barcode1);
Mamphekgo wrote: when i use messagebox to search
I didnt understand where you are applying this message box ? Inside SearchCustomer or where you are using the object. Sorry but i can see only one problem that ur SearchCustomer function should return the Customer name which you will then set in any text box or other controls.
Hope i am guessing it right !
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
the sample code is here: (in .NET Framework 2.0)
<br />
object obj = "abc";<br />
string s2 = obj as string;
string s3 = (string)obj;
string s4 = obj.ToString();
thanks in advance
|
|
|
|
|
If you know that the object contains a string:
string s3 = (string)obj; // method 2
If the object may contain other types of data:
string s2 = obj as string; // method 1
The s2 variable will be null if the object did not contain a string.
If you want a string value whatever the object contains:
string s4 = obj.ToString(); // method 3
The s4 variable will contain the string representation of whatever the object contains. If the object for an example contain an integer with the value 42, you will get the string value "42".
---
b { font-weight: normal; }
|
|
|
|
|
I always use this method to get the string , because I can sure its type is string .
<br />
string s3 = (string)obj;
if the obj is not a string , then it would occur a exception.
|
|
|
|
|
An implicit cast is safer that using 'as', but I am lazy, so I prefer to use 'as'
|
|
|
|
|
<br />
object a = 123;<br />
<br />
try {<br />
string s1 = (string)a;<br />
Console.WriteLine("method 1 value: {0}", s1);<br />
}<br />
catch {<br />
Console.WriteLine("method 1 error.");<br />
}<br />
<br />
try {<br />
string s1 = a as string;<br />
Console.WriteLine("method 2 value: {0}", s1);<br />
}<br />
catch {<br />
Console.WriteLine("method 2 error.");<br />
}<br />
<br />
method 1 error. <br />
method 2 value:
use 'as' can replace try-catch block. haha...
|
|
|
|
|
leppie wrote: An implicit cast is safer that using 'as', but I am lazy, so I prefer to use 'as'
Implicit cast? Don't you mean an explicit cast?
If you use a cast, you will get the exception at the instruction trying to do the cast. If you use "as", you will get a null reference exception somewhere else in the code, when you try to use the reference from the failed cast. Or even worse, it will silently store the value somewhere, and you get the error message weeks later when someone tries to use the stored value...
I always try to write code so that the exception occurs where the error is, then it's a lot easier to locate the source of the error.
---
b { font-weight: normal; }
|
|
|
|
|
Guffa wrote: Implicit cast? Don't you mean an explicit cast?
Hehe, yes
|
|
|
|
|
First:
I'm a fan of strong typed programming (that i think it will prevent many kind of bugs )
So I recommand using string obj="abc";
Second:
But there are times that you should use weak types
then I prefer obj.ToString();
because that one day may be I want to pass another type of object to my method
for example:
object obj=new User();
then my code will not crash but there is one thing that I shoule be aware of :NULL Reference !!! (if obj is null my colde will crash either way)
Then we can a NullSafe static method somewhere in our code
<br />
public static string GetNullSafeString(object obj)<br />
{<br />
return (obj==null?null:obj.ToString());<br />
}<br />
This way I will take advantages of polymorphism (object.ToString() ) and be sure that nothing can harm my code.
Regards
|
|
|
|
|
agree with you about your first point. I know it from a book code complete (2nd)
beatles1692 wrote: First:
I'm a fan of strong typed programming (that i think it will prevent many kind of bugs )
So I recommand using string obj="abc";
P.S the reason I use object obj="abc"; above is to explain my question.
-- modified at 6:01 Wednesday 16th August, 2006
|
|
|
|
|
thanks to all of you. so kind guys.
|
|
|
|
|
WuJunyin wrote: string s4 = obj.ToString(); // method 3
This one is dangerous. While it may work for objects, It may fail for classes, which override the ToString() method.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
hi all, i have 12 buttons each shows a different hidden panel (visible=false) on my form.
i cant edit tab order of my panels because if i try to adjust tab order of a specific panel, all other components on the rest of 11 panels show up
and i do not know how to deal just with the selected panel ?
secondly, if i want to change something (add or remove component) on a specific panel, how can i bring it to front ?
(if i place panels from 1 to 12 respectively, then 1 remains at the bottom and 12 shows at the top)
let's say how i may bring panel8 to the top ?
help please ...
ps: while working on a panel, till now i was resizing the rest 11 panels and placing them at a far corner of my form. but finally when i resized them to their normal state, their components were acting strange due to their dock (anchor) properties. then i spent hours to fix their positions on panels.
|
|
|
|
|
|
guys.....
i am makin an online help for a project ..using java script i am using javascript for tool tip for few words... but that i have to hard core....and that is very very difficult for N number of words.... also for help the pages will increase /decrease from time to time .. and so it will be difficult to maintain and ofcourse it will be stupid to add tool tip for every word especially when that word is called N number of times on same page or other pages
so i was looking for datbase connection ... well there will be a word with tool tip of it in database ... so whenever a page loads ...the code will scan the page and search for words in database and if there is a word in database that is also in the page .. the tool tip should automatically come up .. this tool tip popup will be using javascrit ...
as far as i have gone .. i am not able to do much ... i am able to search /highlight the word on page .... but that not using database .. that i did using an ASP code which includeed a text box in hidden mode and a submit button which enables itselfs on page load... this is workin fine .... but as they say ... there is NO end to technology ... so i want it ....
kamal
-- modified at 5:52 Wednesday 16th August, 2006
|
|
|
|
|
I suggest that think more on the reader when you write. If you write out the whole words, instead of using strange abbreviations like "m", "bt", "b" and "shld", the text gets easier to read. Also, putting the text in proper sentences, instead of writing everyting in a vague unstructured flow, makes it a lot easier to follow.
Then I might have been able to read all of your post and perhaps give some advice. Now I just got halfways through the first paragraph before my mind got occupied by wondering why you write in a manner that does everything to confuse the reader...
---
b { font-weight: normal; }
|
|
|
|