|
You do just like you did in C++, only using managed code. If you need examples, try http://www.google.com[^]. There's many examples out there I've seen in the past.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Did so -> problem solved. Thanks. Note that I actually didn't came from C++, but from Borland Delphi (it's not that bad, really).
|
|
|
|
|
Hi guys,
I think it's a simple question: I connect to a MySQL database with OdbcDataAdapter and besides the data I want to get the schema of the database directly from the database, so I use something like this:
public DataSet GetData()
{
DataSet ds = new DataSet(datasetName);
OdbcDataAdapter adapter = new OdbcDataAdapter();
adapter.SelectCommand = GetSelectAllCmd();
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
adapter.TableMappings.Add("Table", tableName);
adapter.Fill(ds);
if(ds.HasErrors)
ds.RejectChanges();
else
ds.AcceptChanges();
adapter.Dispose();
return ds;
} Everything seems working fine, but the schema isn't transfered correctly. The MaxLength property of the DataColumn member has the value of the longest entry in the database. For example if there is a column called 'name' and the database has an entry like 'John' the MaxLength property is 4. But I specified the 'name' column to allow 100 chars while creating the table (... name VARCHAR(100) NOT NULL, ...).
Furthermore I'm not able to change the MaxLength property. The following has no effect:
ds.Tables[tableName].Columns["name"].MaxLength = 100;
So I'm not able to insert a name to the 'name' column that is longer than 4. I get the error "The value violates the MaxLength limit of this column". Many thanks in advance!!!
Regards, mYkel
P.S.: Sorry I also posted this in SQL/ADO/ADO.NET forum but perhaps it fits better here...
|
|
|
|
|
The schema that you get is relative to the result set. If you want to have a specific schema that matches your tables, I suggest you create a typed DataSet by using either the xsd.exe utility that ships with the .NET Framework SDK to create a typed DataSet class from an XML Schema, or add a new DataSet class in Visual Studio .NET and either re-create your tables (and optionally your keys and relationships), or drag and drop your tables from the Server Explorer after adding a connection object to your database.
Use that typed DataSet in your OdbcDataAdapter calls (like Fill ) and in your queries. If you're using the designer in VS.NET for a DataGrid or some other data-bound control, it gives you nice design-time support for specific table names and columns. If also provides faster access to data when using the typed table and column names because they reference the DataTable and DataColumn objects directly, instead of using a string name that requires several looks ups.
If you don't want to use a typed DataSet , you can also add a columns to your TableMapping property. See the DataTableMapping class and its ColumnMappings property documentation in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I got it working with a typed DataSet ... thanks very much for your help Heath!!! You're the best!
Regards, mYkel
|
|
|
|
|
Hello guys!
I've seen the samples here and I have a few questions:
1 - Is it possible to download the messages with a component and onde they are downloaded I
can't download with outlook?
2 - Can I save the messages in a archive like a pst?
Greetings,
Agus
|
|
|
|
|
|
Hello,
I would like to use the NUnit Framework on GUIs.
Currently I´m using an instance of my form to get all controls. I am then filling some textboxes and push some buttons and 'assert' for errors. But this isn´t working anymore as soon as a modal dialog pops up.
Are there any tools for .NET to do this (like Abbot for JUnit)?
|
|
|
|
|
Simple: How can i use windows API in C#
|
|
|
|
|
Simple: Declare the functions using System.Runtime.InteropServices.DllImportAttribute.
[DllImport("user32.dll")]
private static extern IntPtr GetDC(IntPtr hWnd);
|
|
|
|
|
Hi
I have a problem with type casting . I have the string which is the name of one control(HtmlTable) . I know the control I want to type cast the name as the control.
I tried the following and I get "Invalid Casting ! "
string TableName = "Table1";
(HtmlTable)(TableName)
and
(HtmlTable)((object)(TableName))
Thanks
|
|
|
|
|
Do you know the container of the control? Then you can find the name in the Controls colleciton:
HtmlTable myTable = null;
foreach(Control ctl in container.Controls){
if(ctl.Name == tableName){
myTable = (HtmlTable)ctl;
break;
}
}
If you don't know, where the control is, you can find it "by name":
String tableName = "Table1";
Object ctl = null;
System.Reflection.FieldInfo info = this.GetType().GetField(tableName);
if(info != null){
ctl = info.GetValue(this);
}
HtmlTable myTable = (HtmlTable)ctl;
|
|
|
|
|
Or by referencing the container control, you can use FindControl , passing the name. Cast the return (after checking for null ) to an HtmlTable then.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks that really helped
|
|
|
|
|
How can i convert an xml file to html file. Actually i want to provide the xml file and xsl file to the function and it will give me a file with .htm or .html extension.
Thanx in advance
Regards
minamkhan
Inam
|
|
|
|
|
Take a look at this example:
http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=64
M tti s
|
|
|
|
|
|
|
I don't quite understand what dispose method exacly does. From manual I read that it "frees up ny ressources being used". But what happens to the object after calling dispose method ? Is it destroyer ? Also - is there any link between an object's destructor and dispose method ?
Regards, Desmond
|
|
|
|
|
|
IDisposable.Dispose (you must implement IDisposable for this to be used correctly) is best used to free native resources (since many classes in .NET use native HANDLE s). You can also use it to dispose child objects and set references to null .
This is not a destructor, though. In fact, many times when the Dispose method cleans-up the resources, it will tell the GC to not call the destructor since there's nothing left to do (be sure you clean-up all resources before doing so, though):
public void Dispose()
{
GC.SuppressFinalize(this);
} For a more thorough example, see the documentation for the GC.SuppressFinalize method in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
there is a Garbage Colection 101 article on CodeProject here[^]
-------------------------------
Joan
MomComputerGeek.com
|
|
|
|
|
Hi,
I have two panels side by side.
In runtime, I am adding dyanmic controls to both of panels.
(control label A is insert to Panel1 and Panel2.)
Suppose I insert 50 Labels to both panels. If I move the scroll bar of Panel1, I also want to move the scroll bar of Panel 2 at the same time. How can I do that?
Please show me the way how to do that. I try to use SendMessage Method, but I do not success.
Regards,
|
|
|
|
|
|
Hi Matthew Hazlett
Thank you for your article. After study your articles, I port that code to C#. now I done the scrolling case between two pannels. But I face the other problems. when I put the autoscroll properties "true", I got the autoscroll panel. But I don't want to see auto scroll panel in Panel A. How do I do that? I mean I want to get the same as "Excel". Line Number panel has no "auto scroll".
Thank you for your input.
Regards,
|
|
|
|