|
Respected Christian Graus,
Can you show me any way to solve this problem?
|
|
|
|
|
hi,
i'm now working on this section of project using c# on visual studio .net
this program is suppose to run the automation process in just one/a few clicks.
It's supposed to extract only 1 column, for example, 'Code' from the ms excel file,
In ms excel...
Name | Number | School
---------------------------------------------
Terry | 1234J | ASchool
Tom | 7654P | CSchool
then insert the column of data into the existing ms access file below.
In ms access...
Code | num | Role
----------------------------------------------
10A | 5678Y | Player
10B | 8765R | Player
10C | 1234J | Player //number inserted into column
10D | 7654P | Player //number inserted into column
i would kindly appreciate if anyone would guide me through this, or point to me any existing solutions.
thanks!
;D newbie here~
|
|
|
|
|
Well, at www.connectionstrings.com you'll find the connection strings needed to connect to both Excel and MS Access. I recommend using OleDB. To extract data from one column from excel just create a query like
SELECT * FROM [Sheet1$A1:A100]
Hope this is a good start for you.
I will use Google before asking dumb questions
|
|
|
|
|
thanks for the fast reply
regarding this
SELECT * FROM [Sheet1$A1:A100]
may i know what it means within the [] brackets? is it the worksheet name? if that's the change, the name is prone to frequent changes. are there any ways i can still extract the data regardless name?
|
|
|
|
|
You can get the sheet name using this:
OleDbConnection connection = new OldeDbConnection("...");
DataTable dt = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
You might want to check [this ^] out.
Hope it helps.
I will use Google before asking dumb questions
|
|
|
|
|
! i'll try and work on it now.
Thanks!
|
|
|
|
|
U can found from following links - study below links
http://www.codeproject.com/office/microsoftexcelclient.asp
http://www.codeproject.com/useritems/Excel_Application_in_C_.asp
u can search from dotnetspider.com also
G. Satish
|
|
|
|
|
^^.the links are really useful, helped me a lot.
~will try and work on it now.
Thanks!
|
|
|
|
|
Can anyone tell me how to read the subcode channels in a CD using C#
|
|
|
|
|
Hello...
I habe 2 TreeView. I want to synchronize the scrollbars between that 2 treeView.
So, if I scrolldown the 1 treeView, the 2 treeView will be also scrolldown.
How to do that ?
Thanks...
|
|
|
|
|
Handle the scroll event of control 1, and in it, set the scroll pos of control 2.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello,
As the TreeView has no "Scroll" event you would have to inherit your own TreeView.
There you have to set up your own Scroll event with the use of the overriden "WndProc" method.
This [^] nice article shows how to do it!
All the best,
Martin
|
|
|
|
|
how can i change cultur between control?
i have two textbox on form first text write arabic and second textbox write english
123
|
|
|
|
|
how can i change cultur between control?
example , i have two textbox on form first text write arabic and second textbox write english
123
|
|
|
|
|
public abstract class Test_setting_date_value_base : My_test_base
{
[Step ("2.INHERITED attribute")]
protected abstract bool s2_custom (object data);
protected abstract bool s7_custom (object data);
protected bool s7_goto_datetime_month_value_and_press_ok_up (object data)
{//do something
}
public override BlaTests.Test_step [] get_steps ()
{
Test_step [] steps =
{
s1_initialise,
s2_custom,
//...
s7_custom,
s12_deactivate
};
return (steps);
}
}
public class Test_setting_date_value_1 : Test_setting_date_value_base
{
protected override bool s2_custom (object data)
{
return set_date (30, 11, 2003);
}
protected override bool s7_custom (object data)
{
return s7_goto_datetime_month_value_and_press_ok_up (data);
}
}
Is it possible to do for a class the function that overrides previous implementation by setting 'pointer to function' like in JavaScript? I.e. I want something like that in second class (Test_setting_date_value_1):
protected new bool s7_custom = s7_goto_datetime_month_value_and_press_ok_up ;
I dont' know, but it somehow connected to keyword delegate.
-- modified at 5:14 Thursday 15th November, 2007
|
|
|
|
|
I mean I want that:
Parent has abstract and ordinary method.
Child overloads abstract method with parent's ordinary second method.
So its like I want to assign to abstract method already existant parent's method (or child's method) in the way something like that:
protected bool s7_custom = s7_goto_datetime_month_value_and_press_ok_up ;
//s7_custom - abstract
//s7_goto_datetime_month_value_and_press_ok_up - already defined in parent (or child)
So if s7_custom() called, then s7_goto_datetime_month_value_and_press_ok_up() is called instead.
|
|
|
|
|
Hi all,
Is there a way that I can choose which property of a control to set and then set it, all at runtime?
Let's say I want to set the text on a button at runtime to a string value I read from a file, that's easy. I simply call:
myButton.Text = strMyVal;
The same goes for setting the size, the location or whatever.
However, what if I will only know at runtime which property needs to be set. So I have two variables, strPropertyName and strPropertyValue . How do I set the property of myButton that matches strPropertyName to strPropertyValue ?
I was hoping for something like:
myButton.PropertyByName(strPropertyName) = strPropertyValue;
but to my knowledge there is no such thing as a PropertyByName method.
Any other ideas?
|
|
|
|
|
Hello,
The answere to your problem is "System.Reflection"!
PropertyInfo actPI = yourControl.GetType().GetProperty(yourPropertyName);
if(actPI!=null)
actPI.SetValue(yourControl,yourPropertyValue,new object[0]);
Hope it helps!
All the best,
Martin
|
|
|
|
|
Aaah, sweet! Thanks man. I just love when some comes out with such a quick and straightforward answer that does EXACTLY what I've been looking for.
|
|
|
|
|
Glad I could help!
You are wellcome!
All the best,
Martin
|
|
|
|
|
Martin#, I'm going to push my luck and ask a related question. I'm sure that the answer also lies in reflection somewhere but seeing as it's all new to me and will involve some study I thought I'd see if you could help me.
Would there be a way perhaps of instantiating a new object based on a type that is also obtained during runtime? In other words, I read a file which contains XML (or whatever text based representation of objects) which I then would like to put onto a form.
Let's assume the file holds something like:
Type=Button
Name=MyNewButton
Text=My New Button
Now I can read these into variables, let's call them newType, newName and newText.
How do I instantiate a new object? Again Button newButton = new Button() is easy enough but at runtime it could be Label , TextBox or anything else.
After this is over I promise to make an effort of getting on top of reflection.;)
Thanks,
D
|
|
|
|
|
HEllo,
Also here "System.Reflection" helps you.
string knownAssemblyName = ???;
Assembly asm = Assembly.LoadWithPartialName(knownAssemblyName);
Assembly asm = Assembly.GetExecutingAssembly();
string typeStringOfControl = ???
Type ctrltype = asm.GetType(typeStringOfControl);
ConstructorInfo ci = ctrltype.GetConstructor(Type.EmptyTypes);
object ctrlInstance = ci.Invoke(new object[0]);
All the best,
Martin
|
|
|
|
|
Hi Martin,
Thanks, I really apreciate your help. This method seems to work well, for the most part...
The one problem I have is that ctrlInstance is still of type object even though the Button constructor (or whichever type) is used to instantiate it.
The result is that I can't access any properties that are particular to a specific type directly. For a Button I would like to add an event handler for instance but
ctrlInstance.Click += new System.EventHandler(this.ElementHandler);
wouldn't compile because 'object' does not contain a definition for 'Click'
I was hoping that I could then rather to the following:
PropertyInfo actPI = myControl.GetType().GetProperty("Click");
if (actPI != null)
actPI.SetValue(myControl, new System.EventHandler(this.ElementHandler), new object[0]);
Although this compiles (obviously), it doesn't work because actPI is null .
I hope I'm not getting too tedious with my questions but I appreciate your help.
Dewald
|
|
|
|
|
Hello Again,
Dewald wrote: I hope I'm not getting too tedious with my questions but I appreciate your help.
No way!
This is a very interesting discusion, thanks for that!
Now to your problem:
Reflection in combination with delegates is something I have never done.
So I can only give you a maybe dirty solution (but maybe also the only one possible).
I would cast to the object to the appropriate type and then do your stuff.
...
Button actButton = ctrlInstance as Button;
if(actButton!=null)
{
actButton.Click+=...
}
If you have more than one type to validate for some other action with Label, CheckBox, ...
if(ctrlInstance is Button)
{
Button actButton = ctrlInstance as Button;
actButton.Click+=...
}
else if(ctrlInstance is Label)
{
Label actLabel = ctrlInstance as Label;
}
...
Hope that someone will come up with a cleaner solution,
but maybe it fitts your needs.
All the best,
Martin
|
|
|
|
|
Martin,
I thought of following that approach so if you don't have a more elegant sollution then I suppose I'll just use it. It works fine though but, as you said, it's just not as pretty.
If I may, I'd like to return to the original question quickly. You showed me how to use reflection to instantiate an object of any type and then with the SetValue method of PropertyInfo I can set the value of a property programatically.
I just discovered that, while it works perfectly for properties that have string values, it won't work for property that have a value of some funny type. Take Button.Size for instance, if I have
PropertyInfo actPI = myControl.GetType().GetProperty(myPropertyName);
if (actPI != null)
actPI.SetValue(myControl, myPropertyValue, new object[0]);
with myPropertyName = "Size" and myPropertyValue = "75,24" then obviously I'm going to get into trouble.
I could've used actPI.SetValue(myControl, new Size(100, 24), new object[0]); but I will only know at runtime that the property I'm trying to change is Size and I have to store the value in a file (or DB) in some string representation.
Is there an easy workaround for this?
Cheers,
Dewald
|
|
|
|