|
OK thanks for those comments, it really helped me.
regards.
|
|
|
|
|
Work only with value type and only 1D array.
Example:
using System;
namespace TestUnsafe
{
public class Test
{
[STAThread]
static void Main(string[] args)
{
// Reference type
Console.WriteLine("With a reference type");
TestClass [,] tcArray = new TestClass [2,2];
tcArray[0,1] = new TestClass(2);
tcArray[1,1] = new TestClass(4);
tcArray[1,1].Display();
tcArray[0,1].Display();
// Value type
TestStruct obj = new TestStruct(3);
TestStruct obj2 = new TestStruct(6);
Console.WriteLine("With a value type");
unsafe
{
TestStruct * myObj = &obj; // Value Types only
myObj->Display();
}
Console.WriteLine("With a value type 1D array");
unsafe
{
TestStruct * [] ptrArray = new TestStruct * [3]; // 1D Array only
ptrArray[0] = &obj;
ptrArray[2] = &obj2;
ptrArray[2]->Display();
Console.WriteLine("Loop in the 1D Array");
foreach (TestStruct * ptr in ptrArray)
{
if (ptr != null)
ptr->Display();
}
}
Console.WriteLine("With a value type Jagged Array");
unsafe
{
TestStruct * [][] ptrJaggedArray = new TestStruct * [2][];
ptrJaggedArray[0] = new TestStruct * [2];
ptrJaggedArray[1] = new TestStruct * [2];
ptrJaggedArray[1][1] = &obj;
ptrJaggedArray[1][1]->Display();
Console.WriteLine("Loop in the Jagged Array");
foreach (TestStruct * [] ptrArray2 in ptrJaggedArray)
{
foreach (TestStruct * ptr in ptrArray2)
{
if (ptr != null)
ptr->Display();
}
}
}
}
}
public class TestClass
{
private int data;
public TestClass (int d) { data = d; }
public void Display() { Console.WriteLine(data.ToString()); }
}
public struct TestStruct
{
private int data;
public TestStruct(int d) { data = d; }
public void Display() { Console.WriteLine(data.ToString()); }
}
}
|
|
|
|
|
Hi!
I am developing a web application in asp.net using C# code with sql server 2000 as a db server. I take input from user an populate it in db.now i have problem when i try to insert data in db.
my code is as follows:
SqlConnection myConnection;
private void Page_Load(object sender, System.EventArgs e)
{
myConnection = new SqlConnection("Server=AKRAM;uid=sa;pwd=mypwd;database=HRIS");
Label1.Text="";
}
private void btnSubmit_Click(object sender, System.EventArgs e)
{
String strInsert = "insert into User(UserID,Password,UserType,"+
" FirstName,LastName,Age,Gender,Phone,Fax,Email,URL,"+
" Address,City,State,Country) values (@UserID," +
" @Password, @UserType, @FirstName, @LastName, @Age, " +
" @Gender, @Phone, @Fax, @Email, @URL, @Address, @City, @State," +
" @Country)";
SqlCommand insCommand = new SqlCommand(strInsert, myConnection);
// Create new parameters for the SqlCommand object and
// initialize them to the input-form field values.
insCommand.Parameters.Add(new SqlParameter("@UserID", SqlDbType.VarChar, 20));
insCommand.Parameters["@UserID"].Value = txtID.Text;
insCommand.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 20));
insCommand.Parameters["@Password"].Value = txtPassword.Text;
and so on i provide values to the parameters.
insCommand.Connection.Open()
but following stament comes, error is generated:
insCommand.ExecuteNonQuery();
..
..
..
I m unable to figure out the problem. Can any body help me...
Waiting 4 reply..
|
|
|
|
|
Wrap your insCommand.ExecuteNonQuery(); in a try/catch block and catch the SqlException that gets throw. What does that say?
- Nick Parker My Blog
|
|
|
|
|
Change this...
String strInsert = "insert into User(UserID,Password,UserType,"+
" FirstName,LastName,Age,Gender,Phone,Fax,Email,URL,"+
" Address,City,State,Country) values (@UserID," +
" @Password, @UserType, @FirstName, @LastName, @Age, " +
" @Gender, @Phone, @Fax, @Email, @URL, @Address, @City, @State," +
" @Country)";
Into this..
String strInsert = "insert into User(UserID,Password,UserType,"+
" FirstName,LastName,Age,Gender,Phone,Fax,Email,URL,"+
" Address,City,State,Country) values (?,?,?,?,?,?,?,?,?,?)";
But I'm not sure if this will work, because you are only passing 2 parameters. Do some test with only 2 paramaters... e.g.
String strInsert = "insert into User(UserID,Password) values ?,?)";
Free your mind...
|
|
|
|
|
instead of insCommand.Connection.Open() use
myConnection.Open() and check whether all the server details are correct or not. then try to pass hardcoded values in the query instead of parameters. If it works fine then go to parameters
|
|
|
|
|
Hi Everyone,
I have a problem with a set of components I am creating. Basically I have the following:
Menu : Component<br />
MenuItemCollection : CollectionBase<br />
MenuItem : Component
MenuItemCollectionDesigner
The Menu and MenuItems contain a MenuItemCollection with the following attributes against it
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Editor(typeof(Design.MenuItemCollectionDesigner), typeof(System.Drawing.Design.UITypeEditor))
The designer opens a new form which adds/removes the menu items into the menu/menuitem in a tree style ui.
The items get added ok and are correctly written the InitializeComponent function on the form. The first problem is the fact that the designer does not write out the AddRange call for each MenuItemCollection so the menu items never get added to the collection.
The second problem (the first problem also occured before I introduced this one!) I dont want the menu items to be visible at designtime in the pane on the bottom of the desiger so I added:
[DesignTimeVisible(false), ToolboxItem(false)]
I cant figure out how to delete the items from the code when the parent menu is removed?
I have googled till my fingers bleed, I have seen other peoples similar problems but not really any answer to whats going on with the AddRange method.
One thing I did notice - I Have a custom grid with a custom column collection, the AddRange member for that also stopped working, it did work at 1 point during development, but now both controls dont write out the AddRagne command.
Can anyone help me?
Thanks - James
James Simpson
Web Developer
imebgo@hotmail.com
P S - This is what part of the alphabet would look like if Q and R were eliminated Mitch Hedberg
|
|
|
|
|
As far as removing all the child components recursively when their parent is removed, get the IComponentChangeService service in your designer and handle the ComponentRemoving or ComponentRemoved event. You can recurse through your children and remove them. The designer should reflect this automatically.
As far as adding the components, use a good disassembler (like ildasm.exe that comes with the .NET Framework SDK) or a good decompiler like .NET Reflector[^] and perhaps take a look at how the existing Microsoft.VisualStudio.WindowsForms.MenuDesigner, Microsoft.VisualStudio designer does it.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the reply.
I am downloading the .NET Reflector for a bit of research - thanks for the link.
The other two problems are now sorted.
1) Everything was working fine apart from the fact I was missing the Add call to the collection myself. I was just adding the new component into the Container collection thinking that was sufficient - Doh!
2) I just did a recursive dispose on the Diposing function on the Component and cleared the collections at the end and that solved that one.
Thanks - James
James Simpson
Web Developer
imebgo@hotmail.com
P S - This is what part of the alphabet would look like if Q and R were eliminated Mitch Hedberg
|
|
|
|
|
Hi,
im loosing my hair over this .
if i have a typed dataset with the follwoing tables:
Customer ,Order ,OrderDetails
(northwind db)
and then i add relations to those tables in the dataset designer.
so far so good.
if i then fill each table with a dataadapter everything works fine to.
BUT
if i now only want to fill the "Order" table i get an error complaining that there are constraints problems.
isnt it possible to fill a typed datatable that has parent relations w/o getting this error?
i have solved this in a somewhat dirty way , i remove the parent constraint via code.
is this the only way to do it ??
i find it very strange that i cant just fill a table with the data in the database w/o loading the parent rows first!
//Roger
|
|
|
|
|
This is exactly the way it should be.
Either the typed dataset has, or it hasn't got a constraint. And all the data in that dataset must comply to the constraints that are set on the dataset...
Have a look at my latest article about Object Prevalence with Bamboo Prevalence.
|
|
|
|
|
If you've established a relationship between Customer and Order tables, this adds a relational-integrity constraint such that the Order table has a foreign key relationship with Customers; therefore, you cannot have a key in the Orders table that does not correspond to a primary key in your Customers table.
As far as programmatically removing the relationship or constraint, you could either do that (not much choice! ) or have two strongly-typed DataSet classes. We usually take the latter approach in our app I designed at work. Just makes things easier in the long-run and doesn't add too much bloat to your app/library.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have created a dll in VC++ for customizing a dialog, and now I want to use this from my C# app. But I keep getting an error telling me that an entrypoint can't be found. So I guess I missed out on something when creating my native dll.
What I've done is simply create a new Win32 Dynamic-Link-Library project(MyDll.dll)
This adds the __declspec(dllexport) before the functions.
Then I build my project and copy the dll file into the working directory of my C# project.
The C# code for calling the dll function looks like this:
[DllImport("MyDll.dll")]
public static int sum(int x, int y);
So can anyone help me with why the entrypoint can't be found? Is there more to creating a native dll than this?
I really can't find any useful information for solving this anywhere (at least not useful to me...)
|
|
|
|
|
You can specify the entry point of your code within the DllImport attribute (Specifying an Entry Point[^]), also you need to identify your DllImport attribute with extern .
[DllImport("MyDll.dll", <code>EntryPoint="Sum"</code>)]
public static <code>extern</code> int sum(int x, int y);
- Nick Parker My Blog
|
|
|
|
|
why not create a managed C++ layer directly in the dll?
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Nick is write that you should include the extern keyword in the P/Invoked method declaration:
[DllImport("MyDll.dll")]
public static extern int sum(int x, int y); Also make sure that MyDll.dll is in a directory in the PATH environment variable or the application directory so that it can be found. Examples of such directories are C:\Windows, C:\Windows\System32, etc.
I just wanted to add that you can use depends.exe to make sure your functions are exported as you think they should be. Depends is a great Platform SDK tool and, if you choose the default options when installing VS.NET, should be installed. Just run the "Visual Studio .NET Command Prompt" in your VS.NET programs group off the start menu, cd' to the directory with your native DLL, and type "depends.exe MyDll.dll". If you've added the Platform SDK's bin directory to your system or user PATH environment variable (I like to manage all my PATH, INCLUDE, and LIB directories like this), you can just type "depends" in your Start->Run prompt and load your DLL. That will show you your exports.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Ok, thanks for the advice. so i checked the exported functions with the depends.exe tool, and they seem kind of odd...
the name of my sum(int, int) function is not sum, but rather appears as :
?sum@@YAHHH@Z
in the list over exported functions. No wonder the entry point can't be found I guess...
Do you have any idea what might cause this?
|
|
|
|
|
That's what happens when the function is not declared as a C-style function. The best way to declare the function is like so:
#ifdef _cplusplus
extern "C" {
#endif
INT __declspec(dllexport) sum(INT, INT);
#ifdef _cplusplus
}
#endif
INT __declspec(dllexport) sum(INT a, INT b)
{
return a + b;
} extern "C" declares the functions in the scope with C linkage and the functions won't be decorated. __declspec(dllexport) is a MS calling convention that exports the functions, thus eliminating the need for a .dep file. If you don't use this calling convention, you will have to use a .dep file.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I want to test my web service so I locate it in other computer(with IIS installed and .NET framework),and then create virtual directory in IIS for it and give read and browse directory permission,But when I run a test client and call the web service I HTTP error 405(Method not allowed) ,when I browse the WB from IE the test page does not appear and only a tag appear which say:
<%WebService Language=C# Code-Behind=.....>
Any idea?
Mazy
No sig. available now.
|
|
|
|
|
Sounds like the mappings for ASP.NET files are setup. Run "aspnet_regiis.exe -i" on the machine with ASP.NET installed using the framework you want to easily setup the appropriate mappings (like .aspx, .asmx, etc.). Run "aspnet_regiis.exe -?" for more information.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I want to test distributed application on local machine Before deploying the application
What is the tools that can simulate distributed enviroment ?
And is Microsoft Application Center Test can help in that?
Thanks in advance
|
|
|
|
|
Yes, ACT is for such a purpose. You can also throw together a simple client that spawns several threads all chattering with the distributed app. That's pretty much what all load-testing tools do. If you need to simulate different clients (ex, with different IPs) that gets a little more difficult but not impossible.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks Heath
one more question
in your experience is the test result accurate?
in the case the test scenario related to the real environment
or i need to test again on real environment
thanks in advance
|
|
|
|
|
I'm sorry, but I couldn't tell you. I haven't had the opportunity to test it. I can tell you that lots of people use it, which wouldn't be the case if it were too bad.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
thanks heath
i moved toward distributed application so you may find
me ask many qoustion about this topic
so any suggestion will be appreciated
thanks agai
|
|
|
|
|