|
I'm sorry for my stupidity in this matter, but I obviously just don't get it. Can you give me an example of what you are talking about?
|
|
|
|
|
It's all covered in the .NET Framework SDK. For example:
DataRelation("CustomerOrders",
ds.Tables["Customers"].Columns["ID"],
ds.Tables["Orders"].Columns["CustID"]);
dataGrid1.AllowNavigation = false;
dataGrid1.DataMember = "Customers";
dataGrid1.DataSource = ds;
dataGrid2.DataMember = "Customers.CustomerOrders";
dataGrid2.DataSource = ds; Now you're got two related tables. Selecting a row in the Customers DataGrid (dataGrid1) will show related rows from the Orders table in the Orders DataGrid (dataGrid2). See the DataGrid.DataMember for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
My Table "Adressen" has as PrimaryKey "adid".
When I want to update the Adressen Table occurs an error:
Procedure sp_AdressenUpdate expects parameter @Original_adid which was not supplied.
This error occurs only if I edit a row and update, NOT when I add new Rows and update then.
The parameter @Original_adid exists.
I hope you can help me!
Thanks
Stefan
|
|
|
|
|
STW wrote:
This error occurs only if I edit a row and update, NOT when I add new Rows and update then.
Because it's used only in the DataAdapter.UpdateCommand and, thus, must be added to the DataAdapter.UpdateCommand 's Parameters property. The data adapter designer will do this for you if you opt for it.
The exception would not be thrown if the Parameters property contained the parameter correctly - i.e., it's named "@Original_adid" and is declared as the correct type.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I want to create control inherited from UserControl class. I need this control to be scrollable (I‘m using Autoscroll property) and I want to paint its background with linear gradient brush. When I do this and scroll the control it doesn‘t redraw correctly. Can anybody point me to some tutorial, or at least tell me how to get something like OnScrollEvent (I couldn’t find anything like that in the Control class. thanks
Salut!
|
|
|
|
|
Hi,
Could any one share with me the source in C# for adding, updating and deleting data in a SQL server database using ADO.NET.
A simple windows application would be of great help.
Thanks
Saleem.
|
|
|
|
|
The documentation for the SqlDataAdapter Class[^] in the .NET Framework SDK contains plenty of examples and all the documentation you need. Reading the class library documentation in the .NET Framework SDK is important. If you have a question about a specific class (or struct, interface, method, property, etc.), I recommend you read the SDK documentation first.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have written a short piece of code that goes of to a URL and retrieves and XML formatted file. The file that is returned is dicatated by a URL parameter.
If I go directly to the URL in a browser, the XML document is displayed correctly and fully. When I attempt to do this through code the last quarter of the XML string is made up of escaped 0's (i.e. \0)
The code I have is as follows :
string endPoint = "https://myserver/xmlprovider?id=123";
HttpWebRequest samlRequest = (HttpWebRequest)WebRequest.Create(endPoint);
HttpWebResponse samlResponse = (HttpWebResponse)samlRequest.GetResponse();
Stream responseStream = samlResponse.GetResponseStream();
byte[] buffer = new byte[samlResponse.ContentLength];
responseStream.Read(buffer, 0, buffer.Length);
string returnData = System.Text.Encoding.ASCII.GetString(buffer);
responseStream.Close();
Does anybody know what could be causing this?
post.mode = postmodes.signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
It's either because you're using the wrong encoding (most likely) or because you're trying to buffer way too much.
I remember having this conversation with you before: do not buffer the entire content. Break it apart into smaller buffers. 4096 bytes (4Kb) is typically a good buffer size. Stream it into a file.
The most likely problem, as I said above, is that your encoding is wrong. ASCII characters are 1 byte, where other characters sets range from 1 byte to 4 bytes. UTF8, for example, could be 1 byte or 2 (MBCS). If your response stream is Unicode (UCS-2, or 2 bytes per character), then your byte count would be twice as large as you think it should, and the default byte value is 0 (character '\0').
To get the correct encoding, you should use the HttpWebResponse.ContentEncoding property like so:
Encoding enc;
try
{
enc = Encoding.GetEncoding(response.ContentEncoding);
}
catch
{
enc = Encoding.UTF8;
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Here is a sample of a small c# assembly passing a string array
public enum WeatherType
{
Cloudy=0,
Sunny,
Windy
}
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IWeatherSink
{
//for arrays
string[] WeatherOptions();
[return : MarshalAs(UnmanagedType.LPArray,SizeConst =4)] string[] WeatherOptionsasArray();
}
Now by default,the array is marshalled as safearray ,as confirmed from teh typelib.
Now the second line attempts to marshall the array as LPArray type.
The ATL client invokes these methods as
SAFEARRAY* _safe=cpi->WeatherOptions();
wcstombs(weathertype,(BSTR)_safe[0].pvData,512);
cout << " safearray dimensions " << _safe->cbElements << " " << weathertype << endl;
The invocation of the above is successful.However executing the foolowing
//now receive it marshalled as BSTR* array
BSTR* _bstarray=cpi->WeatherOptionsasArray();
gives the following error
The value of ESP was not properly saved across a function call.
Why is this happening? How should this be invoked
|
|
|
|
|
The ESP register is a stack pointer that is grabbed by the caller and should reference the address of the variable. In this case it is not.
What is wrong with the SAFEARRAY? Simple array pointers should actually not be used in OLE automation, which describes the requirements for OLE clients - a base minimum set of requirements that all OLE-compliant languages/frameworks should follow (kind of like the CLI, only for COM).
That's not to say it's impossible, though. This isn't uncommon with P/Invoke. Because it's a return value, you also don't need to specify SizeConst , which is only used when marshaling from unmanaged to managed code, which does't happen for a return value.
Try this:
[return: MarshalAs(UnmanagedType.LPArray,
ArraySubType=UnmanagedType.BStr)]
string[] WeatherOptionsAsArray();
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I was tryin out the various marshalling options available from managed to unmanaged environmentfor strings and arrays.Hence the adventure of trying to marshall the array as LPArray(as per Andrew Troelsen's book thsi should be possible).
However,the suggestion you gave does not work -it still gives 'The value of ESP was not properly saved across a function call File i386/checkesp.c Line 42'
|
|
|
|
|
i want find a class which can analyse HTTP.
i have the HTTP string,
HTTP 1.0
Connection: keep-alive
Browser: IE40
........
i want input the HTTP string and the class can out put anything i need.
such as System.Web.HttpRequest is very good.but i can't find any method can input string, what class should i use?
|
|
|
|
|
Be patient - you asked this question just a few moments earlier.
Read my response to your previous question.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
When we view any document in print preview dialog, where does it save the document? such that when me move to next/previous page where it reads the information from . If a heavy document like RTF file having images and large number of pages is viewed in PrintPreview, does it affects the system speed? What happens at application level?
please guide
regards
|
|
|
|
|
It's stored in memory, the same as all other objects in an object-oriented application (or even just variables in procedural languages - it's all about memory).
If you have large documents and don't want to buffer them all in memory, then you need to implement drawing routines from cached objects. For instance, if you get an event notificatin that the first page is being drawn, you should have to grab the first page full of what the document contains, leaving the rest on disk (when applicable).
Typically this is not a problem, though. In most applications, when you load a document (Word document, HTML document, Photoshop Drawing document, whatever) the whole thing is loaded into memory anyway. If you draw from that document, then only a single copy is read into memory for both displaying and printing. Certain things can affect this, however.
So, if you make your document class derive from PrintDocument , then you only need to have one reference loaded. When you assign your document object to the PrintPreviewDialog.Document property, for example, a reference is saved - not a copy of the document.
You don't have to derive from PrintDocument , either. Just make sure that any printing routines query your document object for how to print and you can save memory.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have written 3 class libraries and want to share among different applications. How can I do that?
Thanks
|
|
|
|
|
In the Solution Explorer, right-click on the "References" folder and select "Add Reference...". On the .NET tab, click the "Browse..." button and locate your class libraries' *.dll files and add them as needed. From there, they are part of your project and ready for use.
Happy Programming and God Bless!
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|
um.. i mean how can i use the same dll in different applications? i don't want my device to have multiple copies of the dll
thanks
|
|
|
|
|
Install the assembly into the Global Assembly Cache (GAC). You can do this using gacutil.exe that ships with the .NET Framework (the runtime, not the SDK, so every machine with .NET installed will have it), or a Windows Installer project.
When developing the application, you must still reference the DLL when building (and I recommend a Project reference as opposed to a file reference if these projects are in the same solution - just select the Projects tab when adding a reference). When you run the application, however, if the assembly name is found in the GAC (where the CLR first looks) it will use that copy. Otherwise the CLR reverts to a local copy or a location defined in the app's .config file.
To install into the GAC, your assembly must be strong named, which means it must be signed (always a good idea anyway).
To generate a key pair, use:
sn.exe -k KeyFile.snk Use the path to that file in the [assembly: AssemblyKeyFileAttribute[ you typically find in your projects' AssemblyInfo.cs files. I recommend using the same one for all your assemblies, or at least for a particular project.
You should also disable automatic versioning of the shared assembly by getting rid of the asterisk (*) in the [assembly: AssemblyVersionAttribute] (also commonly found in the AssemblyInfo.cs file, though they can go anywhere). If you use automatic versioning, you'll need to install a new copy into the GAC with every change. Instead, just managed the version numbers yourself for much better control.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
To add to what Heath said...
You should have all of the shared DLL's in a single directory. For example, if every developer gets a network shared drive that is a G: drive, then I'd put them in the G:\Shared Utils directory.
Once you get them added to the GAC, then you need to create a single registry key entry:
HKLM/Software/Microsoft/.NetFramework/AssemblyFolders/{companyname}SharedFolder
Then set this key to the value G:/Shared Utils
This is required if you want your shared dll's to show up in the Add Reference dialog under the .NET dll's.
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
want find a class which can analyse HTTP.
i have the HTTP string,
HTTP 1.0
Connection: keep-alive
Browser: IE40
........
i want input the HTTP string and the class can out put anything i need.
such as
System.Web.HttpRequest
is very good.
but i can't find any mother can input string, what class should i use?
|
|
|
|
|
What???
You can use the System.Net.HttpWebRequest and System.Net.HttpWebResponse and get this information using properties like the Headers dictionary property that each class has, such as:
string someHeader = response.Headers["SomeHeader"]; Many HTTP headers has specific properties, like the ContentType . Read over the documentation for the HttpWebRequest and HttpWebResponse class - part of the pluggable protocol implementation - in the .NET Framework SDK.
Class in System.Web.* namespaces are for ASP.NET and should not be used outside of ASP.NET except in uncommon cases and when you know that they can work (unliked the class you mentioned) outside ASP.NET.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i have seen the MSDN.
but it told me.
don't create HttpWebResponse directly,you should get it from HttpWebRequest.GetResponse.
but i don't have any HttpWebRequest.i only kown the HTTP string
GET /?forumid=1649&fr=51 HTTP/1.1<br />
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, *
i want use an analyser to get the HTTP heads and Params. i want input HTTP string and the analyser can give me anything i want,just like System.Web.HttpRequest.
|
|
|
|
|
Then just do simple line parsing? Use a StringReader and loop through the lines. Split the line on the first colon found:
StringDictionary lookup = new StringDictionary();
using (StringReader reader = new StringReader(httpString))
{
string methodAndRequest = reader.ReadLine();
if (methodAndRequest != null)
{
line = reader.ReadLine();
while (line != null)
{
if (line == "\r\n") break;
string[] header = line.Split(new char[] {':'}, 1);
if (header.Length == 2)
lookup.Add(header[0].Trim(), header[1].Trim());
}
}
}
Console.WriteLine(lookup["Host"]); It's a simple parsing algorithm. If you want, you could further break-down known headers to typed classes or whatever you want to do.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|