|
I'm a chinese learner, Use the MatrixClass.cs to want to get my resualts, but can not...
Can you use my arrA,arrB and Matrix to get the resualt? help me, please!
double[,] arrA = { { 99.07, 70, 1.6, 1.1, 0, 0, 25, 0 }, { 0.31, 15.7, 0.45, 0.3, 0, 0, 1.34, 0 }, { 0.05, 0.2, 30.52, 54.5, 0.09, 0, 50, 0 }, { 0.05, 0.2, 21.32, 2.1, 0.08, 0, 0, 0 }, { 0.23, 13, 0, 0, 42.77, 58.2, 0, 72.28 }, { 0, 0, 0, 0, 42.77, 0, 0, 0 }, { 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, -67.2, 0.8, }, { 0, 0, 0, 0, 1.71, 2.3, 0.8, 69.96 } }; ; //array of coefficients
double[,] arrB = { { 72 * 100 }, { 1.2 * 100 }, { 8.3 * 100 }, { 4 * 100 }, { 14.0 * 100 }, { 0.042 * 100 }, { 0 }, { 0 } };
|
|
|
|
|
WHAT????
present the problem/Question, beacuse i can't see it
Have Fun
Never forget it
|
|
|
|
|
|
sgncdc wrote: I'm a chinese learner, Use the MatrixClass.cs to want to get my resualts, but can not...
Why can't you? What is keeping you from getting the result? What do you do to try to get the result, and what happens when you do that? Do you get any error message?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
sgncdc wrote: MatrixClass.cs
What is this and why do you expect us to know about it ? If it's in an article, ask the author in the forum under the article.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
I read data from a database to dataset and diplay it in a datagrid.
Now I want to update database from xml file
First I read update xml file: dataset.ReadXml(fileName);
Now I update database with dataset:
SqlTransaction trans=null;
try
{
string strcnn="Data Source=.;Database=HaSTC;Integrated Security=SSPI";
SqlConnection cnn=new SqlConnection(strcnn);
cnn.Open();
string fileName=@"D:\xml\STS_Stocksinfo.xml";
DataSet ds= new DataSet();
ds=DataReadingFromXMLFile(fileName);
SqlDataAdapter adapter=new SqlDataAdapter("select *from stocks_info",cnn);
trans=cnn.BeginTransaction();
SqlCommandBuilder builder=new SqlCommandBuilder(adapter);
adapter.SelectCommand.Transaction=trans;
adapter.Update(ds,"stocks_info");
trans.Commit();
cnn.Close();
}
catch
{
if(trans!=null)
trans.Rollback();
}
But when I execute it. It has a notice: "Update unable to find TableMapping['stocks_info'] or Table['stocks_info']".
So I can't update my database.
What is the problem? Please tell me clearly
Truong Thanh Dien HUFLIT, VietNam
|
|
|
|
|
is the table name Correct??
The Table name in DataBases are Case Senstive
Have Fun
Never forget it
|
|
|
|
|
Thanks you for your answer
But when I change table name from "stocks_info" to "STOCKS_INFO", nothing change. My program still have a same notice
What is my problem?
Truong Thanh Dien HUFLIT, Vietnam
|
|
|
|
|
Hi,
I can successfully insert data into database fields.
I can also upload file into database field.
However, i wish to combine both in one operation i.e. inserting data into fields as well as uploading file in to another field.
Example of fields: Name, Address, Story (where story is a field to store uploaded file)
Can someone help please
|
|
|
|
|
|
You cannot directly store the file.....but instead you can store the data of the file...let me know the exact data of your file.
Systems Analyst
|
|
|
|
|
Hi,
I want to copy Dictionary Object of one classA to Dictionary Object of classB. The strctures of classA and classB are same. Is it possible to do it? If yes, how?
Here's something I am trying....
classA
{
public string str;
}
classB
{
public string str;
}
classC
{
Dictionary<string, classA> dictA = new Dictionary<string, classA>();
Dictionary<string, classB> dictB = new Dictionary<string, classB>(); //Thanks for poiting out Navaneeth
public someMethod()
{
//some code
dictB = dictA; // HOW TO DO THIS??? I WANT TO COPY (NOT ADD / APPEND) THE ENTIRE COLLECTION
//some code
}
//Other code
}
Cheers,
Vaibhav
<div class="ForumMod">modified on Wednesday, July 23, 2008 11:21 PM</div>
|
|
|
|
|
vaibhav.jape@gmail.com wrote: Dictionary<string, classB> dictB = new Dictionary<string, classA>();
This is invalid and won't compile. Second dictionary can contain key as string and value as any "ClassB " type. How you are expecting "ClassA " type to be copied to there ?
|
|
|
|
|
Dictionary<string, classB> dictB = new Dictionary<string, classA>();
This is invalid and won't compile. Second dictionary can contain key as string and value as any "ClassB" type. How you are expecting "ClassA" type to be copied to there ?
-------------------------------------------------
Thanks for pointing out that Navaneeth, but frankly i was just a type mistake. I am sorry for that!!!
Can you help me now????
Rgds
Vaibhav
|
|
|
|
|
In the Dictionary class you have an overloaded constructor to which you can pass you current Dictionary object and create a copy of the same.
<br />
Dictionary<string, string> abc= new Dictionary<string, string>();<br />
abc.Add("abc","def");<br />
abc.Add("ghi","xyz");<br />
<br />
<br />
Dictionary<string, string> copy = new Dictionary<string, string>(abc);
modified on Wednesday, July 23, 2008 11:18 PM
|
|
|
|
|
You have to relate classA and classB in some way - the easiest being inheritance, or implementing the same interface.
Inheritance - Have a common base class for these two classes, say ClassAlpha.
Then it should become
// create new Dictionary
Dictionary<string,ClassAlpha> dictA = new Dictionary<string,ClassAlpha>();
// Fill this one
// ...
// Create a copy
Dictionary<string,ClassAlpha> dictB = new Dictionary<string,ClassAlpha>(dictA);
|
|
|
|
|
vaibhav.jape@gmail.com wrote: dictB = dictA
This don't work. You want to copy all the ClassA objects value to ClassB object and store in dictB , right ?
class ClassA
{
public string str = string.Empty;
public ClassA(string str) {
this.str = str;
}
}
class ClassB
{
public string str = string.Empty;
public ClassB(string str) {
this.str = str;
}
} To copy values, you can use
Dictionary<string, ClassA> dictA = new Dictionary<string, ClassA>();
dictA.Add("X", new ClassA("First"));
dictA.Add("Y", new ClassA("Second"));
dictA.Add("Z", new ClassA("Third"));
Dictionary<string, ClassB> dictB = new Dictionary<string, ClassB>(dictA.Count);
foreach (KeyValuePair<string, ClassA> pair in dictA) {
dictB.Add(pair.Key, new ClassB(pair.Value.str));
}
|
|
|
|
|
Hello folks.
It's been a while since I've managed to paint myself into a corner - but have no fear - I have not lost my talent for getting in over my head!
This time I am working with reflection and trying to access different classes generically . But I have run into a problem trying to get some information out of an object when the object's class isn't known until runtime:
public void GetDataFromStaticClassX(string MethodToCall, object[]MethodParms)
{
private const BindingFlags StaticMethodBindings = BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod;
private const BindingFlags InstancePropertyBindings = BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty;
private const BindingFlags InstanceMethodBindings = BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod;
object returnedInfo = typeof(X).InvokeMember(MethodToCall, StaticMethodBindings, null, null, MethodParms);
That works: the proper method is called and the result is put in returnedInfo . However, the result could be any of a number of different classes, depending on the value of MethodToCall . The only thing I now for sure about the contents of returnedInfo is that it will implement IEnumerable .
int returnedInfoCount = (int)returnedInfo.GetType().InvokeMember("Count", InstancePropertyBindings, null, returnedInfo , null);
That works too. I can see the proper value being assigned to returnedInfoCount .
Now comes the kicker: I want to access the first entry in returnedInfo . I tried this
object myData = returnedInfo.GetType().InvokeMember("Item", InstanceMethodBindings, null, returnedInfo, new object[] {0});
No luck. The exception says method Item is not found.
returnedInfo.GetType().InvokeMember("MoveNext", InstanceMethodBindings, null, returnedInfo, null);
object myData = returnedInfo.GetType().InvokeMember("Current", InstanceMethodBindings, null, returnedInfo, null);
Also dies - "MoveNext" is not found.
Does anyone have any ideas of how I can get at the first entry in returnedInfo ?
Many thanks if you are kind enough to look into this.
Even more if you have a suggestion/solution/idea/words of encouragement...
edit: small error in the example code
Clive Pottinger
Victoria, BC
modified on Wednesday, July 23, 2008 6:54 PM
|
|
|
|
|
Not sure I understood you correctly, but if your type implements IEnumerable,
that means exactly one thing: it has a GetEnumerator() method.
So take it from there, get that Enumerator and use it, IMO no further reflection is required.
And a foreach would do that automatically, so why don't you try:
foreach(MyType item in myEnumerableType) {
item.SomeMethod();
}
|
|
|
|
|
Thanks Luc, but it won't work. However, building on your example may make it a little simpler to illustrate my problem:
public void myGetData(string myEnumerableTypeName)
{
object myEnumerableType = (code that returns myEnumerableType as an object)
foreach(MyType item in myEnumerableType)
{
item.SomeMethod();
}
}
Note that I have myEnumerableType, but only as an instance of an object, and objects don't implement IEnumerable.
If I could cast myEnumerableType as an IEnumerable object, then I could write
foreach(MyType item in (IEnumerable)myEnumerableType) But, IEnumerable is an interface, so casting is not allowed.
If I could dynamically implement IEnumerable, perhaps
foreach(MyType item in myEnumerableType:IEnumerable) but the Gods of Syntax threw a bolt of lighting at me for just suggesting it.
I can get the original type of myEnumerableType
Type origType = myEnumberableType.GetType(); Again, if I could dynamically cast then I could do
foreach(MyType item in ((Type)origType)myEnumerableType) but that time the GoS punished me by replacing all my screensavers with jpegs of Ugly Betty.
Clive Pottinger
Victoria, BC
|
|
|
|
|
Hi Clive,
First a few minor corrections to your message:
cpotting wrote: but only as an instance of an object, and objects don't implement IEnumerable.
- objects are instances of classes
- classes can implement an interface
- objects can be cast to an interface, the compiler will accept, the run-time check
may fail; in your case, it cannot prove the object IS an instance of an IEnumerable
class, so it refuses to cast.
Now IMO this is the right plan of attack:
- get your object;
- use reflection to execute its GetEnumerator() method and store the result as a
new object (of type IEnumerator), say myEnumerator.
- on myEnumerator, call methods Reset(), MoveNext() and the property Current
as you see fit; no need for reflection here.
This is code I have running:
public override void Run(int arg) {
MyList list=new MyList();
IEnumerator ienumer= typeof(MyList).InvokeMember("GetEnumerator", InstanceMethodBindings, null, list, null)
as IEnumerator;
log("ienumer="+ienumer);
while (ienumer.MoveNext()) log((string)ienumer.Current);
}
public class MyList : IEnumerable {
private List<string> list=new List<string>();
public MyList() {
list.Add("aaa");
list.Add("bbb");
list.Add("ccc");
}
public IEnumerator GetEnumerator() { return list.GetEnumerator(); }
}
</string></string>
Hope this helps.
modified on Wednesday, July 23, 2008 8:58 PM
|
|
|
|
|
Luc Pattyn wrote: Now IMO this is the right plan of attack:
- get your object;
- use reflection to execute its GetEnumerator() method and store the result as a
new object (of type IEnumerator), say myEnumerator.
- on myEnumerator, call methods Reset(), MoveNext() and the property Current
as you see fit; no need for reflection here.
This is code I have running:
public override void Run(int arg) {
MyList list=new MyList();
IEnumerator ienumer= typeof(MyList).InvokeMember("GetEnumerator", InstanceMethodBindings, null, list, null)
as IEnumerator;
log("ienumer="+ienumer);
while (ienumer.MoveNext()) log((string)ienumer.Current);
}
public class MyList : IEnumerable {
private List list=new List();
public MyList() {
list.Add("aaa");
list.Add("bbb");
list.Add("ccc");
}
public IEnumerator GetEnumerator() { return list.GetEnumerator(); } // LINE WAS MISSING!
}
Thanks again, Luc.
I did not see this and your next post until after I posted my answer. But it is enlightening to see your approach anyway.
There would be two problems with implementing the solution you give above:
1) It requires the me to declare ienumer as type IEnumerable . I do not have this ability (I think it is because we are still using .NET 2.0 here).
2) the line
while (ienumer.MoveNext()) log((string)ienumer.Current); requires that the type returned by ienumer.Current be hardcoded as string . But I cannot hardcode the type, because, in my situation, I may be working on MyList , or MyIntList , or MySomeOtherClassList ...
None the less, your suggestions got me past both issues and my code is working wonderfully. I know I would still be floundering about if it wasn't for guru's like you and the rest of the TheCodeProject folks.
Cheers!
Clive Pottinger
Victoria, BC
|
|
|
|
|
Hi Clive,
You're welcome. Yours was an interesting question, and I happened to have been
investigating IEnumerable and IEnumerator all day. My reflection experience is
limited so I took the opportunity you offered.
cpotting wrote: It requires the me to declare ienumer as type IEnumerable. I do not have this ability (I think it is because we are still using .NET 2.0 here).
I have been running my tests targetting 2.0
But ienumer is an IEnumerator, not an IEnumerable, maybe that got you fooled somehow.
cpotting wrote: requires that the type returned by ienumer.Current be hardcoded as string.
I am not saying you must do it this way, the only thing I meant was once you got
an IEnumerator, it is a real one, you can use it with managed code without reflection,
but yes you have to somehow cast Current to the appropriate type so you can really
use it. But this may well be doable with little or no reflection. Certainly
the MoveNext() does not need reflection at all.
|
|
|
|
|
Hi Clive,
FYI: I just learned that static classes can't implement interfaces, maybe that is
what held you back. My experiments were on instances right away, but I just tried
to simplify to something static and started to get compile errors.
Of course, an explicit call to a GetEnumerator method is always possible, and
a properly implemented Enumerator always returns a new object, with its own
current pointer, so multiple enumerators could be walking the same IEnumerable
at their own pace.
|
|
|
|
|
An even cleaner approach is by replacing the Invoke statement by:
IEnumerator ienumer=(IEnumerator)typeof(IEnumerable).
InvokeMember("GetEnumerator", InstanceMethodBindings, null, list, null);
|
|
|
|
|