System.Type.GetType("System.Data.SqlTypes.SqlString") problem

  • Thread starter Thread starter spider
  • Start date Start date
S

spider

Hi,
I'm trying to create a DataColumn with the following code:

DataColumn dc = new DataColumn("CustomerID",
System.Type.GetType("System.Data.SqlTypes.SqlString"));

but the GetType method does not return a valid type.
If I use "System.String" it works.
If I create an instance of System.Data.SqlTypes.SqlString and the use the
instance's GetType method inherited from System.Object I can get the type
but I would like to get the type directly from Type.GetType.

Can anyone see what I'm doing wrong?
Is there another way to get what I need with a single method call?

Thanks...Ron
 
DataColumn dc = new DataColumn("CustomerID",
System.Type.GetType("System.String"));

I think that should do it for you. I know you said if
you use System.String it works, but you can use it with
GetType and it should still work.

Hopefully this answers it, but if not let me know.

Good Luck,

Bill

W.G. Ryan
(e-mail address removed)

-----Original Message-----
Hi,
I'm trying to create a DataColumn with the following code:

DataColumn dc = new DataColumn("CustomerID",
System.Type.GetType("System.Data.SqlTypes.SqlString"));

but the GetType method does not return a valid type.
If I use "System.String" it works.
If I create an instance of
System.Data.SqlTypes.SqlString and the use the
 
Bill,

Thanks for the code but when I said System.String I meant using it with
Type.GetType exactly like the code that you sent.
What I'm trying to do is use specific System.Data.SqlTypes if I can. I
think underneath that's what happens but I wanted to do it explicitly and
save .NET the work.
I did find a way to do it but it's messy (using the fully qualified type
name) .
DataColumn dc = new DataColumn("CustomerID",
System.Type.GetType("System.Data.SqlTypes.SqlString, System.Data,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));

But then I ran into another problem when I tried to set the dc.MaxLength. I
got an error saying that MaxLength applies to string data type only. I would
think that SqlString is a string data type but I get the error.

I think I'll just use System.String and not fight it.
Thanks for the help...Ron
 
Remember that DataTable objects are members of
System.Data, they aren't pegged to SqlClient or
OledbClient or anything else.

Now, if you want to take advantage of native DB types, a
way to do it is to create a Datatable as normal and then
take each column and pass the value's in as
Parameters...the command object is included in each
respective library so you can type it's parameters. In
your case,SQL is going to send varchar fields as varchar,
small int's as ints etc from the Database, but the
datatable will make it fit into a close type. Then you
can take these types, and get each value, change it into
the respective SqlDbType and pass it back.

I hope this helps, let me know if not.

Good Luck,

Bill

W.G. Ryan
(e-mail address removed)
www.knowdotnet.com
-----Original Message-----
Bill,

Thanks for the code but when I said System.String I meant using it with
Type.GetType exactly like the code that you sent.
What I'm trying to do is use specific
System.Data.SqlTypes if I can. I
 
Back
Top