|
If you derive from DataColumnCollection , override its indexer to return an instance of myColumn instead of DataColumn , and override the Columns property in myTable to use your new custom column collection, you can avoid the cast.
Charlie
if(!curlies){ return; }
|
|
|
|
|
Charlie,
I'm not quite sure I undestand your suggestion..
pls, give me a sample..
Thx.
|
|
|
|
|
Hi meyi
What you have done is correct. That is defining two different class myTable from System.Data.DataTable and myColumn from System.Data.DataColumn.But did you make the columns propery of you class myTable as myColumn.If you didn’t still it is the type of DataColumn even that class is your’s.Thatswhy you need to cast it as myColumn to access myProperty. So you verify the datatype of Column property of myTable.
Still you have the same problem send your complete code I will try to fix it.
Feel free to contact me.
tnx..;)
M.Sendilkumar
Senior Software Engineer
TVS Infotech Ltd
Chennai,India.
|
|
|
|
|
Hi SendilKumar
As you can see in the code, the properties 'Id' and 'Name' in Debtable class.. -I have the same problem with the property 'Columns' that is derived from the System.Data.DataTable
I have to use casting to System.Data.DataColumn
If you can solve this issue lots of my headaqe wil be gone
Thx..
//My BaseTable
using System;
using System.Data;
using System.Reflection;
using System.Collections;
namespace Data
{
///
/// Summary description for BaseTable.
///
public abstract class BaseTable : System.Data.DataTable
{
#region contructors
public BaseTable(string name) : base(name)
{
this.InitializeComponent();
}
#endregion contructors
#region methods
///
/// Initiate all columns owned by the Table.
///
private void InitColumns()
{
IEnumerator columns = this.GetType().GetProperties().GetEnumerator();
PropertyInfo property;
columns.Reset();
while(columns.MoveNext())
{
property = (PropertyInfo) columns.Current;
if(property.PropertyType.ToString() == typeof(Column).ToString())
property.GetValue(this, null); //Just call the getter of the property to initiate the instance
}
}
private void InitializeComponent()
{
((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
//
// BaseTable
//
this.InitColumns();
((System.ComponentModel.ISupportInitialize)(this)).EndInit();
}
#endregion methods
#region properties
public abstract System.Data.DataTable DataTable
{
get;
}
#endregion properties
}
}
//My Column
using System;
using System.Data;
using System.Reflection;
using System.Collections;
namespace Data
{
///
/// Summary description for Column.
///
public class Column : DataColumn
{
private bool systemColumn = false;
private bool indexColumn = false;
public Column(): base()
{
}
public Column(string name, string caption, TypeCode dataType): base(name,TypeCode2Type(dataType))
{
this.Caption = caption;
this.DataType = TypeCode2Type(dataType);
}
public Column(string name, string caption, TypeCode dataType, bool mandatory): base(name,TypeCode2Type(dataType))
{
this.Caption = caption;
this.DataType = TypeCode2Type(dataType);
this.AllowDBNull = mandatory;
}
public Column(string name, string caption, TypeCode dataType, int maxLength): base(name,TypeCode2Type(dataType))
{
this.Caption = caption;
this.DataType = TypeCode2Type(dataType);
if(dataType == TypeCode.String)
this.MaxLength = maxLength;
}
public Column(string name, string caption, TypeCode dataType, int maxLength, bool mandatory): base(name,TypeCode2Type(dataType))
{
this.Caption = caption;
this.DataType = TypeCode2Type(dataType);
if(dataType == TypeCode.String)
this.MaxLength = maxLength;
this.AllowDBNull = mandatory;
}
static Type TypeCode2Type(TypeCode typeCode)
{
return Type.GetType("System."+typeCode.ToString());
}
public SqlDbType Type2SqlDbType(System.Type type)
{
if(type == TypeCode2Type(TypeCode.Boolean))return SqlDbType.Bit;
if(type == TypeCode2Type(TypeCode.Byte)) return SqlDbType.TinyInt;
if(type == TypeCode2Type(TypeCode.Int16))return SqlDbType.SmallInt;
if(type == TypeCode2Type(TypeCode.Int32)) return SqlDbType.Int;
if(type == TypeCode2Type(TypeCode.Int64)) return SqlDbType.BigInt;
if(type == TypeCode2Type(TypeCode.Decimal)) return SqlDbType.Decimal;
if(type == TypeCode2Type(TypeCode.Single)) return SqlDbType.Real;
if(type == TypeCode2Type(TypeCode.Double)) return SqlDbType.Float;
if(type == TypeCode2Type(TypeCode.Char)) return SqlDbType.NChar;
if(type == TypeCode2Type(TypeCode.String)) return SqlDbType.NVarChar;
if(type == TypeCode2Type(TypeCode.DateTime)) return SqlDbType.DateTime;
if(type == TypeCode2Type(TypeCode.Object)) return SqlDbType.Variant;
return SqlDbType.Variant;
}
#region Properties
public bool SystemColumn
{
get{return this.systemColumn;}
set{this.systemColumn = value;}
}
public bool IndexColumn
{
get{return this.indexColumn;}
set{this.indexColumn = value;}
}
#endregion Properties
}
}
//Finaly a table
using System;
using System.Data;
namespace Data.Tables
{
///
///
///
public class DebTable : Data.BaseTable, IDebTableColumns
{
public DebTable() : base("DebTable")
{
InitializeComponent();
}
public DebTable(string name) : base(name)
{
InitializeComponent();
}
private void InitializeComponent()
{
//
// DebTable
//
this.PrimaryKey = new Column[] {this.DataColumns.Id};
}
///
/// Gets the Column owned by this Table.
///
public IDebTableColumns DataColumns
{
get {return this;}
}
public override System.Data.DataTable DataTable
{
get{return (System.Data.DataTable) this;}
}
#region IDebTableColumns Members
public Column Id
{
get
{
if (this.Columns["Id"] == null)
{
this.Columns.Add(new Column("Id", "ID", TypeCode.Int32, true));
((Column) this.Columns["Id"]).Unique = true;
((Column) this.Columns["Id"]).IndexColumn = true;
}
return (Column) this.Columns["Id"];
}
}
public Column Name
{
get
{
if (this.Columns["Name"] == null)
{
this.Columns.Add(new Column("Name", "Name", TypeCode.String, 30));
}
return (Column) this.Columns["Name"];
}
}
#endregion IDebTableColumns Members
}
public interface IDebTableColumns
{
Column Id
{
get;
}
Column Name
{
get;
}
}
}
|
|
|
|
|
Hi
Let me take a day.
M.Sendilkumar
TVS Infotech Ltd
|
|
|
|
|
hi,
The answer that i am going to explain you is something different. actuall i wrote an article about datagrid formattings. If you see the code, there i am updating the value of datacolumn properties. So my suggection is the entire article you may not need. But you can see the code where i am updating the properties of tables.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
S r e e j i t h N a i r,
It's a interesting arcticle you have wrote... but unfortunately your article
doesn't answer my issue..
My problem is the property 'Columns' in myTable that is inherited from System.Data.DataTable and the return type for this property is System.Data.Column collection.
What I want is to get this property 'Columns' return, type of myColumn collection instead of System.Data.DataColumn collection.
I have uploaded my code.. prev thred..
thx.
|
|
|
|
|
How do I create a form (or other container) that can be docked to one side of the screen?
For example, the taskbar can be docked to a side. When it is docked, Windows recognizes that the virtual screen size is decreased, and maximized windows only maximize to the edge of the taskbar.
Any ideas?
|
|
|
|
|
|
|
i want to know that how can Terrarium deal with cutomers code in DLL?
i want to know the particular process, thanks!
|
|
|
|
|
sssa2000 wrote:
Terrarium
Isn't that what turtles live in ?
( in other words, what you talkin' about, Willis ? )
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
There#s a .NET demo application framework where people can put in their own "animal" DLL's competing for ressources Something like that.
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist Fold With Us! || Agile Programming | doxygen
|
|
|
|
|
Terrarium is a game, in the game you can define a animal by your code.
|
|
|
|
|
Hi,
I am still new in the programming world. I would like to learn how to design a report, and fill its data from programming part, the data of course is take from database (Access Or SQL)
Last time i ask my friend they said , they usually use ttx file to create the field in the report. So, then we store the data from programming part, said from query, i try to do the same thing using C#.NET but it can't work.
Please I need your help.
Daniel Mahadi
|
|
|
|
|
Here's the fast way of creating a report...
- Create a typed dataset
- Add a crystal report file to your project
- As a datasource select ADO.net and navigate to the dataset. Complete the wizard selecting any fields that you need to use
- Save any changes to the crystal report
- Crystal reports generates a typed wrapper for the report. Create an instance of that class.
MyReport r = new Report();
- Fill your dataset
- Pass the data into the the report object by doing this...
r.SetDataSource(dataset);
- add a crystal report viewer control to you form
- passed the report object to the view control
crystalReportViewer1.ReportSource = r;
This should work. Have fun
|
|
|
|
|
Hello,
Can anybody tell me here, how i can use StoredProcedures in a SQL Server CE Database? - Do the storedProcedures which i create in my VS.NET for my Smart Device Application automatically be transfered to the PocketPc when i will deploy it?
thx
regards
mat
|
|
|
|
|
mathon wrote:
Can anybody tell me here, how i can use StoredProcedures in a SQL Server CE Database?
SQL CE does not support stored procedures.
Regards,
João Paulo Figueira
Embedded MVP
|
|
|
|
|
Oh okay, are you sure? - because when i create a new replication i can choose to publish also the stored procedures??
Unfortunately i have a second question: Is it possible like normal databases of the SQL Server 2000 to create databases, tables in the Server Explorer of the VS.NET. Is it possible to create databases for the SQL Server CE also like this in VS.NET??
Regards
mathon
|
|
|
|
|
mathon wrote:
Oh okay, are you sure?
Pretty sure!
mathon wrote:
because when i create a new replication i can choose to publish also the stored procedures??
Did you see what happens to the replicated stored procedures?
mathon wrote:
Is it possible to create databases for the SQL Server CE also like this in VS.NET??
You will be able to do that with SQL Mobile, not with SQL CE 2.0. To help with this, I have developed a tool to help port databases to and from SQL CE. Have a look at it on my website:
Primeworks[^]
Regards,
João Paulo Figueira
Embedded MVP
|
|
|
|
|
HEy guys Ive made a program in C# and I want to open notepad when a user presses a particular button how do i do that
|
|
|
|
|
Usually this type of question goes purposely unanswered cuz its so easy to find the solution, but i'll give it to you...
System.Diagnostics.Process.Start("C:\windows\notepad.exe");
|
|
|
|
|
As AK suggested, you can just do a call to the process object:
System.Diagnostics.Process.Start(@"C:\windows\notepad.exe");
But, I'd suggest you rather "start" the file directly:
System.Diagnostics.Process.Start(@"C:\test.txt");
This way, the default text editor will be started with the file.
It saves a bit of code as you don't need to set up parameters to pass to the process, but it also gets around a issue when the admins install windows under a different folder or something similar.
HTH
Cheers,
Simon
sig :: "Don't try to be like Jackie. There is only one Jackie.... Study computers instead.", Jackie Chan on career choices.
article :: animation mechanics in SVG blog:: brokenkeyboards "It'll be a cold day in Hell when I do VB.NET...", Chris Maunder
|
|
|
|
|
hi
I have this code to retrive all users who are connected to a server . but i need to retrive the passwords of each user and i stucked their.
any one can help me ?
please help me !!
|
|
|
|
|
Passwords are not really ment to be given out anyway... so your probably going to have a hard time to get them... unless there's a security bug.
What server are you talking about?
|
|
|
|