|
hi
thanks for your answer but i would like to check with your if Ole db provider for Excel have the ability to change the cell border and such?
e.g add new sheet, change cell border and font size etc
because most of the articles i read on the net only shows the method of read and writing for it
|
|
|
|
|
You cannot do that with ole db provider. You will need to use excel com object model for that.
|
|
|
|
|
Hi
I am dynamically declaring types (using ModuleBuilder.DefineType[^] which are used to allow for strongly typed data sets from a CSV file.
However when the user adds or alters a column definition I'd like to remove and rebuild the data type. Any ideas how I drop and recreate a type - do I have to unload the whole assembly or how is it done?
public static Type MakeTypeForColumns(string typeName, MarketRecObjects.ImportFileFormatColumnDefinitionCollection columns)
{
Type columnType = null;
TypeBuilder columnTypeBuilder = GetTypeBuilder(typeName);
if (null != columnTypeBuilder)
{
foreach (ImportFileFormatColumnDefinition col in columns)
{
FieldBuilder colFieldBuilder = columnTypeBuilder.DefineField(MakeValidObjectCodeName(@"_" + col.ColumnName),
col.GetTypeForContentType(), FieldAttributes.Private);
PropertyBuilder colPropertyBuilder = columnTypeBuilder.DefineProperty(MakeValidObjectCodeName(col.ColumnName),
PropertyAttributes.None, col.GetTypeForContentType(),
Type.EmptyTypes);
MethodBuilder colGetMethodBuilder = columnTypeBuilder.DefineMethod(@"get_" + colPropertyBuilder.Name, MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName, colFieldBuilder.FieldType, Type.EmptyTypes);
ILGenerator colGetMethodGenerator = colGetMethodBuilder.GetILGenerator();
colGetMethodGenerator.Emit(OpCodes.Ldarg_0);
colGetMethodGenerator.Emit(OpCodes.Ldfld, colFieldBuilder);
colGetMethodGenerator.Emit(OpCodes.Ret);
MethodBuilder colSetMethodBuilder = columnTypeBuilder.DefineMethod(@"set_" + colPropertyBuilder.Name, MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName, typeof(void), new Type[] { colFieldBuilder.FieldType });
ILGenerator colSetMethodGenerator = colSetMethodBuilder.GetILGenerator();
colSetMethodGenerator.Emit(OpCodes.Ldarg_0);
colSetMethodGenerator.Emit(OpCodes.Ldarg_1);
colSetMethodGenerator.Emit(OpCodes.Stfld, colFieldBuilder);
colSetMethodGenerator.Emit(OpCodes.Ret);
colPropertyBuilder.SetGetMethod(colGetMethodBuilder);
colPropertyBuilder.SetSetMethod(colSetMethodBuilder);
}
ConstructorBuilder columnConstructorBuilder = columnTypeBuilder.DefineConstructor(MethodAttributes.Public,
CallingConventions.Standard,
Type.EmptyTypes);
ILGenerator constructorGenerator = columnConstructorBuilder.GetILGenerator();
constructorGenerator.Emit(OpCodes.Ret);
columnType = columnTypeBuilder.CreateType();
}
else
{
columnType = ModuleBuilder.GetType(MakeValidObjectCodeName(typeName), false , false ) ;
}
return columnType;
}
where the type is defined by
private static TypeBuilder GetTypeBuilder(string newTypeName)
{
if (ModuleBuilder.GetType(MakeValidObjectCodeName(newTypeName), false, true) == null)
{
try
{
TypeBuilder ret = ModuleBuilder.DefineType(MakeValidObjectCodeName(newTypeName), TypeAttributes.Public | TypeAttributes.Sealed);
return ret;
}
catch (System.ArgumentException argEx)
{
System.Diagnostics.Trace.TraceError(argEx.ToString());
return null;
}
}
else
{
return null;
}
}
|
|
|
|
|
AFAIK you can't drop code without dropping the entire AppDomain.
You can add code to an existing class, not replace it.
|
|
|
|
|
OK thanks - I'll just have to add a version number to the typename and keep track of the type(s) internally...
|
|
|
|
|
you're welcome.
|
|
|
|
|
Hello,
i have a .NET 2 Application (Class Library) and want to interact with a .NET 3 Application (WPF), how is this possible?
Of course i could reference from the WPF-App to the Class-Library (thats the normal way) but i'm must be able to initiate the .NET 3 App from the .NET 2 Application.
And of course they need to be able to communicate with each other... how can i do that?
Why do i want to do that? Because i want to let my logic in the .NET 2 App and create a GUI-Layer in .NET 3.5 and one in .NET 2 (if the user doesn't have 3.5 or doesn't want it or want to use mono)
|
|
|
|
|
How about a three-part approach:
- a 2.0 EXE with GUI
- a 3.5 EXE with WPF-based GUI
- a 2.0 DLL with all the logic, used by both EXEs.
You can stuff these three projects in a single VS2008/10 solution, and set the target for each project separately.
|
|
|
|
|
Yes, as i wrote that's the "normal" way.
But i need to initiate the GUIs from the logic. Because the logic is used by a host as a "plugin" you can say. So i need to go that way.
<br />
<br />
Logic (2.0)---> WPF GUI (3.5)<br />
|<br />
|<br />
V<br />
WinForms GUI (2.0)<br />
<br />
So how can i do this the easiest way?
|
|
|
|
|
You mean the logic must be the .exe file? Why?
If you are just talking about callbacks, simply make the GUIs implement an interface defined in the logic assembly.
|
|
|
|
|
I'm not sure there's any problem to begin with. Are you experiencing a problem? If so, what?
|
|
|
|
|
I tried the following:
class MonthRec
{
string month_text;
string month_value;
}
private void run_code()
{
List<MonthRec> MonthList = new List<MonthRec>();
MonthList.Add(new MonthRec(){month_text = "January 2009", month_value = "012009"});
}
but getting month_text inaccessible due to protection level
same error for month_value
|
|
|
|
|
By default if you don't specify an access modifier the scope of fields in a class default to private. Make both month_text and month_value public and you will be able to access them.
|
|
|
|
|
better yet, provide a constructor that accepts initial values and stores them.
|
|
|
|
|
i did declare as public but now I am getting three columns!
1. Column with value myappname.myformname+MonthRec
2. month_value with no value
3. month_text with no value
|
|
|
|
|
you should not make public what does not need to be public; my suggestion was and is keep the data members private (or protected) and provide a means to set them, either through properties or through a new constructor that takes initial values.
|
|
|
|
|
DataTable dt = ExecuteQuery("SELECT * FROM Book");
dt.Columns.Add("ImageColumn",typeof(Image));
for (int i = 1; i < dt.Rows.Count; i++)
{
dt.Rows[i]["ImageColumn"] = Image.FromFile(Application.StartupPath + "\\Photo\\pic"+ i +".jpg);
}
....
pictureBox1.DataBindings.Add(new Binding("Image", dt, "ImageColumn"));
B.E.H.Z.A.D
|
|
|
|
|
Hi guys,
Actually i have an xml file which is given below :
<ApplicationIndex>
<Row>
<ID>CCP</ID>
<ApplicationDescription>Consolidated Liability Report</ApplicationDescription>
<Category>CM</Category>
<Business_Owner></Business_Owner>
<CreatedID></CreatedID>
<CreatedTimeStamp></CreatedTimeStamp>
<Status>A</Status>
</Row>
<Row>
<ID>CAPRC</ID>
<ApplicationDescription>CAPRC</ApplicationDescription>
<Category>CM</Category>
<Business_Owner></Business_Owner>
<CreatedID></CreatedID>
<CreatedTimeStamp></CreatedTimeStamp>
<Status>A</Status>
</Row>
<Row>
<ID>ICC</ID>
<ApplicationDescription>ICC</ApplicationDescription>
<Category>CM</Category>
<Business_Owner></Business_Owner>
<CreatedID></CreatedID>
<CreatedTimeStamp></CreatedTimeStamp>
<Status>A</Status>
</Row>
</ApplicationIndex>
Now i hav created a console application which reads this file the coding is as follows :
using System;
using System.Data;
using System.Data.Odbc;
using System.Xml;
using System.Configuration;
using System.IO;
namespace ConsoleApplication1
{
class Class1
{
public void perform()
{
OdbcConnection con= new OdbcConnection();
ADIBCrypto.Encryption64 crpto = new ADIBCrypto.Encryption64();
try
{
string connString = crpto.GetCnnStr(ConfigurationSettings.AppSettings["appname"],ConfigurationSettings.AppSettings["dsnSybase"]);
con.ConnectionString = connString;
con.Open();
Console.WriteLine("Connection Opened Successfully");
XmlDataDocument doc = new XmlDataDocument();
doc.Load(ConfigurationSettings.AppSettings["dest"]);
XmlNodeList nodes = doc.GetElementsByTagName("Row");
foreach(XmlNode node in nodes)
{
if(node.HasChildNodes && node.ChildNodes.Count > 0)
{
string ID = node.ChildNodes[0].Value;
string ApplicationDescription = node.ChildNodes[1].Value;
string Category = node.ChildNodes[2].Value;
string Business_Owner = node.ChildNodes[3].Value;
string CreatedID = node.ChildNodes[4].Value;
string CreatedTimeStamp = node.ChildNodes[5].Value;
string Status = node.ChildNodes[6].Value;
Console.WriteLine("{0}",ApplicationDescription);
}
}
con.Close();
Console.WriteLine("Connection Closed");
Console.ReadLine();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
static void Main(string[] args)
{
Class1 cc = new Class1();
cc.perform();
}
}
}
now on the output field i get only null values (a blank) but i checked dat it reads the xml file and also checked whether it
returns the name of the xml node everything is fine... the only
problem is that now it doesnt give me the value of the child node.. please do help me...
(my actual aim is to copy all these records into my db.. that is why i hav db connections in my coding... that i will deal
with if the current problem is solved)
Thanx in advance....
modified on Tuesday, December 8, 2009 4:03 AM
|
|
|
|
|
Hi,
Did you tried to use the "InnerText"-property instead of "Value"-property?
Regards
Sebastian
|
|
|
|
|
Awesome dude... i was really breaking my head.. thanx alot..
regards,
Thashif
|
|
|
|
|
Even though my prob is solved can u please tell me why dint it return the value of the child node when used the statement
string ApplicationDescription = node.ChildNodes[1].Value;
I was confused actually....
Regards,
Thashif
|
|
|
|
|
XmlNode is a base class representing all types of "nodes" within an xml document. So the implementation of "value" doesn't fit for all subtypes. I guess that the nodes you are reading will be represented by XmlElement. For this the "Value"-property is null and you have to use "InnerText" or "InnerXml".
Have a look here at MSDN, where it is described:
http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.value.aspx[^]
Regards
Sebastian
|
|
|
|
|
|
Basically, use InnerText for Elements and Value for Attributes.
|
|
|
|
|
Hi Guys and Gals.
I have a simple question, but for the life of me cant find an answer out there.
I have a string that will contain an Expression: string x = "(2+3)+((7*2)-5)";
I need x to execute now as an expression in order to get the result of the expression.
Eg. decimal y = (2+3)+((7*2)-5); [This is the value from the text string x]
Result in y = 14
Your help will be greatly appreciated or your guidance to a possible workable solution.
Kind Regards,
Elizma
|
|
|
|