|
Is there a direct way to access a datatable in a collection directly by its name?
Currently, the only way I know how access a datatable is by using a foreach statement to find the table I wish to update/modify:
DataTableCollection tables = collection.Tables;<br />
<br />
foreach (DataTable tbl in tables)<br />
{<br />
string name = tbl.TableName;<br />
<br />
if (name == "name")<br />
{<br />
DataRow myNewRow;<br />
myNewRow = tbl.NewRow();<br />
<br />
code.....<br />
<br />
tbl.Rows.Add(myNewRow); <br />
<br />
}<br />
}
Thanks for any help
|
|
|
|
|
Umm... perhaps DataTableCollection.Item[^]
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Thanks for the answer. I've not used datatable collections before and was spinning my wheels. So I can replace the foreach loop with:
DataTable table = tables["name"];
|
|
|
|
|
Yep. Should work for all collections!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
ds = DB.FillDataSet(cmd, "StRecord");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
foreach (DataColumn col in ds.Tables[0].Columns )
{
}
From: <ahref="http: www.programlive.tk"="">http://www.programlive.tk
|
|
|
|
|
I have written a program in C# using inpout32.dll which, when you press a button, it sets all the data pins on the paralell port to high by setting the address as 888 and the decimal value 255 to that address. I have heard that when a pin on the port is a high, it is outputting a voltage of 5v, but it shows about 1.5v constantly, not changing, while none of the other data ports do anything. I have a feeling this is not working because I either have the wrong address, or I am setting the wrong value.
In my BIOS, it says that the address is 378h, which I know if 888 in decimal, which is why I am setting it as the address. I also have the mode set to EPP. Can somebody tell me what I am doing wrong?
|
|
|
|
|
I don't know. I've used that in one small app. My code is:
[
System.Runtime.InteropServices.DllImportAttribute
(
"INPOUT32"
,
SetLastError=true
,
EntryPoint="Out32"
)
]
private static extern void
API_Out32
(
System.Int32 Port
,
System.Int32 Data
) ;
public static void
WriteToPort
(
System.UInt16 Port
,
System.Byte Data
)
{
API_Out32
(
Port
,
Data
) ;
return ;
}
PIEBALD.Lib.LibApi.WriteToPort ( 0x378 , (byte) this.tvStati.Tag ) ;
|
|
|
|
|
hi, i want to store 2 strings which are named "player" and "score" ,
how do i create a table for this and i want to know how to display this information ...
thanks for all your help
|
|
|
|
|
XML
<Game>
<Players>
<Player Name="Joshua" Score="42" />
</Players>
</Game>
How you display it is up to you.
|
|
|
|
|
Won't that give InsaneDataException at name?
|
|
|
|
|
What? I said Joshua, not HAL.
|
|
|
|
|
You need to get some books on databases and start reading...
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Store them where? In memory, database, text file, ...
Display them how? On screen, console, printer, ...
Try and describe your problem in clearer terms.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
For loading a file that was originally written by an application written in C++, I have been declaring each part of the file as a struct, and converting the data into a struct using this function:
public static TStruct GetStruct<TStruct>(byte[] data,Type t)
where TStruct : new()
{
int structSize = Marshal.SizeOf(typeof(TStruct));
TStruct outstruct = new TStruct();
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
outstruct = (TStruct)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),t);
handle.Free();
return outstruct;
}
This works fine for structs that do not contain arrays or that contain only arrays that can be defined using fixed (eg fixed int someVariable[10]; works fine) ,but I run into a problem when I want to do this to a struct such as:
struct Foobar
{
int count;
customStructType someStruct[count];
}
I've tried using [MarshalAs(UnmanagedType.<tried all these>, <parameters specified type takes here>)] but it either requires me to specify a fixed number upfront or causes my GetStruct method to give me an error that it "could not meaningfully obtain the size of the struct". LPArray allowed me to specify a particular element in the struct that acts as the number of elements in the array but that gave me the aforementioned lack of meaningful size error. Is there any way to make this work?
|
|
|
|
|
Nasty one. AFAIK .NET does not allow any direct coding that will create a structure whose length is not fixed at compile time - and I can understand why not.
I haven't tried it, but this[^] appears to address the problem. In a suitably nasty way, of course...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Hi everyone..
I am getting the above error in one of the application on this portal.
The application is:
http://www.codeproject.com/KB/IP/CSNetworkSniffer.aspx?msg=3625563#xx3625563xx
I am really new to socket programming so i need your help
Thank you and any help would be appreciated
|
|
|
|
|
Try posting your question in the forum at the end of the article, and then the author should get notified.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
It uses raw sockets to sniff TCP/IP, which cannot be done in Windows XP SP2 and above for security reasons. If you want to run this code, you'll need to do it on Windows Server 2003 and above.
From MSDN on Raw Socket limitations:
On Windows 7, Windows Server 2008 R2, Windows Vista, and Windows XP with Service Pack 2 (SP2), the ability to send traffic over raw sockets has been restricted in several ways:
•TCP data cannot be sent over raw sockets.
•UDP datagrams with an invalid source address cannot be sent over raw sockets. The IP source address for any outgoing UDP datagram must exist on a network interface or the datagram is dropped. This change was made to limit the ability of malicious code to create distributed denial-of-service attacks and limits the ability to send spoofed packets (TCP/IP packets with a forged source IP address).
•A call to the bind function with a raw socket is not allowed.
These above restrictions do not apply to Windows Server 2008 , Windows Server 2003, or to versions of the operating system earlier than Windows XP with SP2.
|
|
|
|
|
This is my scenario: I have a huge database and I'm building numerous services to access the data.
Each service exposes a unique set of data and services to the consumer.
So for an object such as Company our internal service needs the raw address in the composite. However our portal service need fully enumerated Address info in the composite.
I wanted to avoid having a massive object with various composite addon's that don't apply to a given object but I'm running into difficulties.
First I decided that each composite builder class will be in a namespace deeper than the data namespace. So instead of myApp.Data it would be myApp.Data.Mainservice and myApp.Data.Portalservice for the composite objects.
My next step was to inherit Company, add a constructure that takes Company as input to populate internal fields, and add the DataMember for each Composite that is needed. Works great but I get a runtime error that I cannot inherit an object that is not marked as Serializable or DataContract.
Initially I just added a public partial class Customer and added the DataContract attribute, but that does not expose the DataMembers inside of the object.
I also cannot use the partial class definition as I need to be inside the namespace of the Customer object which puts me back into the same problem of having an accumulation of composite objects.
For those who need pictures here is the code I want to implement:
namespace Company.Data.InternalServices
{
[DataContract]
public sealed class CompositeLocation : Company.Data.Location
{
[DataMember]
public Address LocationAddress{get;set;}
}
[ServiceContract]
public class InternalContract:IInternalContract
{
[OperationContract]
public CompositeLocation GetLocation( Guid LocationIdentity );
}
}
namespace Company.Data.Portal
{
[DataContract]
public sealed class CompositeLocation:Location
{
[DataMember]
public EnumeratedAddress{get;set;}
}
[ServiceContract]
public class PortalContract:IPortalContract
{
[OperationContract]
public CompositeLocation GetLocation(Guid LocationIdentity);
}
}
When no method returns a Location, WCF drops the DataContract for Location. I want to force it to keep Location as a data contract!!!
|
|
|
|
|
I have a software which requires activation. I am going to save the user registration data on my sql server database on my host (online) via the WinForm registration form.
DO you recommended to do a normal sqlConection from the WinForm to the sql server online to syore the data?
or it's better to develop a web service for that?
what do you think?
|
|
|
|
|
Web Service
You should never expose the SQL server to public access outwith a private network unless you really really really must....
Dave
Find Me On: Web| Facebook| Twitter| LinkedIn
CPRepWatcher now available as Packaged Chrome Extension, visit my articles for link.
|
|
|
|
|
I wonder why not?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Yeah, it is all too dogmatic for me, resulting in loads of unnecessary complexity.
Just put the database layout, username and password on the web site. Keep it simple.
Or skip the whole activation thing.
|
|
|
|
|
Username and password will do - you can query the table structure from the DB.
I wonder why Microsoft don't do that?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
As DaveAuld says, go for the web service.
Presumably, you are using software activation as a way of securing your income and preventing piracy. If you expose your sql connection publicly so the WinForm app can access it, do you think that helps? Or creates a big security hole for naughty people to jump right through and pre-activate as many copies as they want?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|