|
Hey guys,
I'm trying to check the uniqueness of the index key of visual foxpro tables. From the tableinfo table I read all names of the tables in the database and the name of their index key.
The name, index key and path (omniwinroot) are stored in an instance of class ActiveTable named tableToAnalyze
Next I invoke a member method of ActiveTable (Analyze.Table) on that instance.
This executes 2 queries on the table. The first one counts all the records, last one counts only those with distinct index key.
If there are less unique index keys then there are rows in the table then the UNunique index keys are safed in a queue (so it could be fixed later).
The goal is to copy (by value) tableToAnalyze to a list of instances of ActiveTable when double index keys were found.
So something like this:
<br />
Class classVar = new Class();<br />
list<Class> classList= new List<Class>();<br />
<br />
classVar.integer1 = 1;<br />
classVar.integer2 = 3;<br />
<br />
if (condition) classList.Add(classVar);<br />
From there i could display in a datagridview and prompt the user to repair (only those tables he wants to repair).
The code I have seems to copy by reference. After all the tables are analyzed my list holds 2 (which is correct) of the same values. Both hold the values of the last table
What am i doing wrong?
private void dubbelNummeringToolStripMenuItem_Click(object sender, EventArgs e)<br />
{ <br />
string sqlQueryTableInfo ="SELECT ctableid, flocation, ctablename, caliasname, cidfield, cidindex, cdatabase FROM tableinfo WHERE (cdatabase = 'dpatient') AND (flocation = 'data') AND (cidfield <> '') ORDER BY ctablename";<br />
string connectionStringTableInfo = "Provider=VFPOLEDB.1;" + "Data Source=" + omniwinRoot + "\\tableinfo.dbf";<br />
<br />
OleDbCommand commandTableInfo = new OleDbCommand(sqlQueryTableInfo);<br />
<br />
ActiveTable tableToAnalyze = new ActiveTable();<br />
List<ActiveTable> tableToAnalyzeList = new List<ActiveTable>();<br />
<br />
using (OleDbConnection ConnTableInfo = new OleDbConnection(connectionStringTableInfo))<br />
{<br />
try<br />
{<br />
ConnTableInfo.Open();<br />
commandTableInfo.Connection = ConnTableInfo;<br />
OleDbDataReader readerTableInfo = commandTableInfo.ExecuteReader(CommandBehavior.CloseConnection);<br />
while (readerTableInfo.Read())<br />
{<br />
tableToAnalyze.omniwinRoot = omniwinRoot;<br />
tableToAnalyze.table = readerTableInfo.GetString(3).Trim();<br />
tableToAnalyze.tableKey = readerTableInfo.GetString(4).Trim();<br />
tableToAnalyze.AnalyzeTable();<br />
tableToAnalyze.verschil = tableToAnalyze.tableRecords - tableToAnalyze.tableUniqueRecords;<br />
if (tableToAnalyze.verschil > 0)<br />
{<br />
tableToAnalyzeList.Add(tableToAnalyze);<br />
}<br />
<br />
}<br />
ConnTableInfo.Close();<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message + Environment.NewLine + "While opening tableinfo table an error occured." + Environment.NewLine + "Make sure OmniWin is not running.");<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
public class ActiveTable<br />
{<br />
public string omniwinRoot;<br />
public string table;<br />
public string tableKey;<br />
public int tableRecords;<br />
public int tableUniqueRecords;<br />
public int verschil;<br />
Queue<string> doubleKey = new Queue<string>();<br />
<br />
public void AnalyzeTable()
{<br />
string connectionStringDpatient = "Provider=VFPOLEDB.1;" + "Data Source=" + omniwinRoot + "\\data\\dpatient.dbc";<br />
string queryNumberRows = "SELECT " + tableKey + " FROM " + table + " WHERE (nversionid = 0) " + "ORDER BY " + tableKey;<br />
string queryDistinctRows = "SELECT DISTINCT " + tableKey + " FROM " + table + " WHERE (nversionid = 0) " + " ORDER BY " + tableKey;<br />
string queryGetNotDistinctId = "SELECT " + tableKey + ", count(*) AS count FROM " + table + " GROUP BY " + tableKey + " HAVING count > 1";<br />
try<br />
{<br />
OleDbConnection ConnDpatient = new OleDbConnection(connectionStringDpatient);<br />
OleDbCommand command = new OleDbCommand(queryNumberRows);<br />
command.Connection = ConnDpatient;<br />
ConnDpatient.Open();<br />
<br />
tableRecords = command.ExecuteNonQuery();<br />
<br />
command.CommandText = queryDistinctRows;<br />
tableUniqueRecords = command.ExecuteNonQuery();<br />
if (tableRecords - tableUniqueRecords > 0)<br />
{<br />
command.CommandText = queryGetNotDistinctId;<br />
try<br />
{<br />
OleDbDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);<br />
while (reader.Read())<br />
{<br />
doubleKey.Enqueue(reader.GetString(0).Trim());<br />
}
|
|
|
|
|
Creating a new instance of the ActiveTable variable should do the trick into your while loop
while (readerTableInfo.Read())
{
tableToAnalyze = new AnalyzeTable();
tableToAnalyze.omniwinRoot = omniwinRoot;
tableToAnalyze.table = readerTableInfo.GetString(3).Trim();
tableToAnalyze.tableKey = readerTableInfo.GetString(4).Trim();
tableToAnalyze.AnalyzeTable();
tableToAnalyze.verschil = tableToAnalyze.tableRecords - tableToAnalyze.tableUniqueRecords;
if (tableToAnalyze.verschil > 0)
{
tableToAnalyzeList.Add(tableToAnalyze);
}
}
|
|
|
|
|
That did the trick indeed.
I thought about it but couldn't understand why this would help.
Still don't, hoping to come across an answer in the coming days.
(studying c# for work)
Anyway, thanks a lot.
|
|
|
|
|
Because you were reassigning the properties of the same instance each time. Thats why you got the same object twice in your list because the object is by reference.
With the modification, you'll create a new instance of the object on each iteration and each object in your list will be different because they point at their own reference.
Hope that help
|
|
|
|
|
Yes, that helped
thanks
|
|
|
|
|
i have two forms ChatManagerForm and ChatWindowForm, and i have a bool variable in ChatManagerForm to indicate that the ChatWindowForm is opened or not.
i want to set this variable to false at ChatWindowForm closing, here i think about two choices.
first: make the variable static,and keep the ChatWindowForm refrence and then
access the variable from the ChatWindowFrom instance.
second: use delegetes and events(pass message from ChatWindowForm to ChatManagerForm).
what is the best, the most practical.
or any other suggestions.
thanks in advance
|
|
|
|
|
|
cant you just use myChatWindowForm.Visible ?
|
|
|
|
|
I would use a delegate and event.
public delegate ChatWindowClosingHandler(object sender, EventArgs args);
public interface IChatWindowManager {
void ChatWindowClosing(object sender, EventArgs args);
}
public partial class ChatManagerForm : Form, IChatFormsManager{
public event ChatWindowClosingHandler OnChatWindowClosing;
public void ChatWindowClosing(object sender, EventArgs args){
}
public ChatManagerForm(){
InitializeComponent();
this.OnChatWindowClosing += new ChatWindowClosingHandler( ChatWindowClosing );
}
}
public partial class ChatWindowForm : Form {
public ChatWindowForm( IChatFormsManager cfm ){
InitializeComponent();
this.FormClosed += new ChatWindowClosingHandler( cfm.ChatWindowClosing );
}
}
I have not had a chance to test the above code but I've used this design pattern many of times. I guess you've gotten three differnet answers to your question. lol. I hope this is helpful.
I'm listening but I only speak GEEK.
|
|
|
|
|
can u plz provide me with the chunk of code for the image
|
|
|
|
|
s_khan_876 wrote: the image
The use of the definite article implies that we know what you are talking about. We don't.
What, exactly, do you want to do? And what part of that are you needing help with?
|
|
|
|
|
...because he's using Cryptography.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
He's posted elsewhere and seems coherent... I think he's just drunk. Can we add an item to the posting guidelines that says if you're too drunk to drive you're too drunk to post?
|
|
|
|
|
Oh, no, we must welcome that posts:
let's say better post than drive when one is such drunk
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hello,
i have a webbrowser control in my c# app. if i click on a link which includes php parameter like
"http://www.mySite.com/myscript.php&var=test" the navigating events fires up.
but when i check e.Url.AbsolutePath only "http://www.mySite.com/myscript.php" is being returned.
how do I get the complete url with all parameters in the navigating event of the webBrowser control?
thanks in advance, Opaknack
|
|
|
|
|
Where can I find a comprehensive explaination of "How to store images in a Resource File and later get these images programatically?" Are there programs available for working with Resource Files? (I am new to this area of C#)
(Code Examples would be very helpful)
Joseph Stanish
|
|
|
|
|
If you are working with Visual Studio 2005 just add a resource file to the project (RESX) and the IDE will let you add whatever resources you need and provide a class to retrieve them for you.
|
|
|
|
|
Placing images in the resource file is easy, but how do I get to these images programatically?
I am creating controls using code, and based on two loop indexes I know the image file name.
For example: IMAGE0000.JPG, IMAGE0001.JPG, IMAGE0100.JPG, IMAGE0101.JPG to load four images using a loop
For x = 0 to 1
For y = 0 to 2
newPic.image =
<br />
Next y<br />
Next x <br />
<br />
<div class="ForumSig">Joseph Stanish</div>
|
|
|
|
|
I want to retrieve a row from a stored procedure specified by the primary key
how can i do that.... what would be the definition of the stored procedure..
and how would i receive them in my c# code....help needed..
The table contains columns:C_Name,C_Capital,C_Currency,C_President of type nchar.
Thanks..
Regards,
Mujz..
|
|
|
|
|
I would recommend buying a book on SQL and reading through it. The ADO.NET stuff you can probably get from the web. What you're asking for is the first example anyone is likely to learn in SQL, and it's
select C_Name, C_Capital, C_Currency, C_President from myTable where primaryKey = x
and x is obviously a parameter to the stored proc.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
can somebody tell me how to read an excel sheet. Are there some specific classes to read excel data..
Plz dont send links coz i've tried them n its not working some example would be highly appreciated.....
Thanks
Regards;
Mujz
|
|
|
|
|
Mujz......... wrote: Are there some specific classes to read excel data..
No.
Mujz......... wrote: Plz dont send links coz i've tried them n its not working
Well, the info on the web obviously works for hte people who wrote it, you need to read them again. Do you have Excel ? The microsoft interop stuff doesn't work without office.
Mujz......... wrote: some example would be highly appreciated.....
How would an example typed into this forum differ from the examples already on the web ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi
I have a large application written in C# with SQL server2000 as database
the application is running ok for 2 years now , limitation in Datagrid in C# 1.1 is the only headache facing me when mdifying this application . my quastion is regarding the upgrade to 2.0 for the full application , can 2.0 run the older 1.1 with no modifcations at all , and does the enhancement in 2.0 for the DataGrid in particular and C# in general worth migrating the application into 2.0 . and if so , we have to update the .NET framework on the users machines . is that a straight forward process .
Thanx
unitecsoft@hotmail.com
We will either find a way , or make one .
|
|
|
|
|
I moved a 1.1 app to 2.0, a big one, and didn't have any real issues.
unitecsoft wrote: and if so , we have to update the .NET framework on the users machines . is that a straight forward process .
There's no upgrade, you leave 1.1, and put 2.0 on as well. So, it's very simple, you just install 2.0
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanx Christian for your reply
That is good , but it raises few more quastions , If .NET 1.1 and 2.0 can exist together on the same development machine , what about user machine , can .NET frameworks 1.1 and 2.0 exist on the same machine ? is .NET 1.1 framework services included within .NET 2.0 ? If I have an application compiled under 1.1 can it run directly on a user machine which has .NET 2.0 , and the opposite ?
Also my main quastion regarding DataGrid in C# 2.0 , is it different / better than DataGrid in C# 1.1 , as per my experiance Datagrid in 1.1 is a headache .
Dean
unitecsoft
We will either find a way , Or make one .
|
|
|
|