|
it works here, with datatable and regular cells.
<br />
DataTable dt = new DataTable("temp");<br />
dt.Columns.Add("col1");<br />
dt.Rows.Add("row1");<br />
dt.Rows.Add("row2");<br />
dt.Rows.Add("row3");<br />
<br />
Console.WriteLine(ColumnEqual(dt.Rows[1][0], dt.Rows[1][0]));<br />
Console.Read();
--> This outputs True (can test it in an empty console app).
You should check it with the debugger, using breakpoints, to see what values are actually compared.
Visual Studio can't evaluate this, can you?
public object moo<br />
{<br />
__get { return moo; }<br />
__set { moo = value; }<br />
}
|
|
|
|
|
Hi joo,
I used MessageBox to show me the comparison, row by row, and they do have the same string in the object (object.ToString()).
They don't compair to true if left in the object (This only happends if the DataTable is populated by ADO). If building the DataTable by code (as in your example), this works fine.
Ron
|
|
|
|
|
It still works when I use ADO...
Your problem appears to be very strange.
SqlConnection conn = new SqlConnection("connstring");<br />
SqlDataAdapter da = new SqlDataAdapter("select * from [table]",conn);<br />
DataSet ds = new DataSet();<br />
da.Fill(ds);<br />
dataGridView1.DataSource = ds;<br />
<br />
Console.WriteLine(ds.Tables[0].Rows[1][1] == ds.Tables[0].Rows[1][2]);
Console.WriteLine(ds.Tables[0].Rows[1][1] == ds.Tables[0].Rows[1][1]);
Visual Studio can't evaluate this, can you?
public object moo<br />
{<br />
__get { return moo; }<br />
__set { moo = value; }<br />
}
|
|
|
|
|
Yes, I spent hours trying to figure out why it was not grouping. Finally, I tried changing the object to a string right at the compairison (a.ToString() == b.ToString()) and magically the grouping worked.
Damn, I guess I have to go to work (day job).
Ron
|
|
|
|
|
Yes, it is probably a good solution. But I still think it's strange that it didn't work before, because here in my sandboxapp it does. Weird.
Have fun working
Visual Studio can't evaluate this, can you?
public object moo<br />
{<br />
__get { return moo; }<br />
__set { moo = value; }<br />
}
|
|
|
|
|
Hi again joon,
I've been playing around with the stock code again...
I've noticed that if you try and Group By the other columns (OrderID",Int32) [I did change a few rows so some are the same value], it will not group. The stock code only seems to group on a string column? Could you check it our with your sandboxapp?
thanks,
Ron
|
|
|
|
|
OK, I see now...
I'm a fairly new programmer (with no formal training), so I'm not familiar with object comparison. The other methods (min, max) use IComparable, but they don't bother using it for the ColumnEqual method.
I've changed:
return (a==b); //value type standard comparison
to:
if (((IComparable)a).CompareTo(b) == 0)
return true;
else
return false;
works great now, on the different data types and my OleDbCommand string results.
Ron
|
|
|
|
|
The comparison is not right. Having an empty string is not the same as having a null string. What you want to do is expand your checks for this:
private bool ColumnEqual(string a, string b)
{
if (string.IsNullOrEmpty(a) && string.IsNullOrEmpty(b))
return true;
if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(b))
return false;
return (a == b);
}
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thanks Pete,
Yes, I was also worried about null strings too, but I did a test to see what output I would get.
When you convert a DBNull.Value to string, the result is String.Empty. I'll use IsNullOrEmpty, just to be safe though.
Ron
if (DBNull.Value.ToString() == null)
{
MessageBox.Show("null");
}
else if (DBNull.Value.ToString() == "")
{
MessageBox.Show("empty string");
}
else
{
MessageBox.Show("not null or empty");
}
|
|
|
|
|
hi..
i'm writing a utility package for my tool..
i want a method to be used globally that can be called with out
object or its class name.. is it possible.
plz help me..
regards,
nas
|
|
|
|
|
Hello,
Have you tried a static method?
All the best,
Martin
|
|
|
|
|
A public static class with public static methods is probably as close as you can get. Then you can just use Class.DoMethod() from anywhere where the class is available (same project or it's in a reference, don't forget using directive)
<br />
namespace Globality<br />
{<br />
public static class GlobalClass<br />
{<br />
public static void MyMethod()<br />
{<br />
}<br />
}<br />
}<br />
and then somewhere else
<br />
using Globality<br />
<br />
GlobalClass.MyMethod();<br />
Visual Studio can't evaluate this, can you?
public object moo<br />
{<br />
__get { return moo; }<br />
__set { moo = value; }<br />
}
|
|
|
|
|
you could have a public static delegate declared in your app and then assign it when the object containing the method you want to call is instantiated.
Russell
|
|
|
|
|
Hi,
Best way is to show you what I want:
SQL Database:
SqlConnection connection = new SqlConnection(connectionString);<br />
SqlCommand getTableList = connection.CreateCommand();<br />
string command = "Select name from sysobjects where type = 'U'";<br />
getTableList.CommandText = command;<br />
connection.Open();<br />
string tables = getTableList.ExecuteScalar().ToString();<br />
connection.Close();<br />
MessageBox.Show("We got ..\n" + tables);
How do I store the results of the SQL Command?
The command appears to work OK but only the name of the first table is recorded in "tables".
Ideally I would like to put the results of the SQL command into an array.
TIA.
Glen Harvy
|
|
|
|
|
Glen,
You only get the first table because you're using the executeScalar method.
To get what you want you need to use the executeReader.
Your code would thus be smth like:
SqlConnection connection = new SqlConnection(connectionString);
string command = "Select name From sysobjects where type ='U'";
SqlCommand getTableList = new SqlCommand(command, connection);
myConnection.Open();
SqlDataReader reader = getTableList.ExecuteReader(CommandBehavior.CloseConnection);
List<string> tables=new List<string>();
while(reader.Read())
{
tables.Add(reader.GetString(0));
}
reader.Close();
//Implicitly closes the connection because CommandBehavior.CloseConnection was specified.
This should get you the list.
Greeting
Kaine
|
|
|
|
|
I agree fully with Kaine.
just an alternate method when using a reader.
SqlDataReader reader = getTableList.ExecuteReader();
and then continue to add to the tables, while using reader.Read().
Keshav Kamat
India
|
|
|
|
|
Thansk for that - much appreciated.
Glen Harvy
|
|
|
|
|
Hi All,
I have some old project that implement some GUI in MFC.
I need to change one of the dialog in this GUI - and i found out that i can do it in very easy way in C#.
Can / How can i mix between those two language ? i want to do in in the easy way - but i don't want to write all the application in C# ... Someone have a idea ?
Thanks for any help.
|
|
|
|
|
|
how to call crystal report
|
|
|
|
|
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True"
ReportSourceID="CrystalReportSource1" DisplayGroupTree="False" HasExportButton="False"
HasToggleGroupTreeButton="False" Height="1106px" Width="751px"></CR:CrystalReportViewer>
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
<Report FileName="CrystalReportOrderDetails.rpt">
<Parameters>
<CR:Parameter ConvertEmptyStringToNull="False" DefaultValue="24994" Name="@ORDER_NUMBER"
ReportName="" />
</Parameters>
<DataSources>
<CR:DataSourceRef DataSourceID="ObjectDataSource1" TableName="InvoiceDetails" />
</DataSources>
</Report>
</CR:CrystalReportSource>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="InvoiceDetails"
TypeName="Kings.OrdersDB" OldValuesParameterFormatString="original_{0}">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="24994" Name="ORDER_NUMBER" QueryStringField="OrderNo"
Type="String" />
</SelectParameters>
|
|
|
|
|
Hi all
I'm trying to use a .Net dll in deployment custom actions, when a add the primary output from the dll to the deployment application and the set the custom actions to the dll the properties windows require an "Entry Point" i have searched every concievable source i know of and have not found a example or solution. Plenty examples where the project installer class is inserted into the application project.
would appreciate your help
Thanks in advance.
|
|
|
|
|
I am making a http request to a html file placed on a Apache server.
On this page there is an embeded perl statement which requires
reading environment variables.
The contents of the page change according to the environment variables.
When I am typing the url of the html page in my browser, I am able to
read the Environment variables and getting the desired results.
But, when I am making Http request through my window application, it
is unable to read the the environment variables.
Please help me out.
The code used is given below:
private void GetFile(string FilePath)
{
using (WebClient wcDownload = new WebClient())
{
string strFile ="test.xml";
try
{
// Code for reading the html file from the server
String downloadUrl = @"http://www.mysite/
folder_job.html";
HttpWebRequest webRequest =
(HttpWebRequest)WebRequest.Create(downloadUrl);
webRequest.Timeout = 15000;
webRequest.Credentials =
CredentialCache.DefaultCredentials;
webResponse =
(HttpWebResponse)webRequest.GetResponse();
Int64 fileSize = webResponse.ContentLength;
strResponse = wcDownload.OpenRead(downloadUrl);
//End Code
strLocal = new FileStream(strFile,
FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
int bytesSize = 0;
byte[] downBuffer = new byte[4096];
while ((bytesSize = strResponse.Read(downBuffer,
0, downBuffer.Length)) > 0)
{
strLocal.Write(downBuffer, 0, bytesSize);
}
strResponse.Close();
strLocal.Close();
webResponse.Close();
}
catch (Exception ee)
{
MessageBox.Show(ee.ToString());
}
}
}
|
|
|
|
|
I want to write a program to copy the computer screen and save it as a bit map file in c#.
Still i couldn't figure out how to start it.
I search in Code Project. But all those answers are so huge.
All i want is a simple program to capture the still picture and save it.
Hope someone could give me at least a clue on how to start this.
Thank you.
rangaSL
|
|
|
|
|