How do I convert a FileInfo.Attributes to a SqlDBType

G

Guest

I'm trying write a SQLCLR that returns FileInfo.Attributes property to SQL
Server in a record set and I am getting the following error.

cannot convert from 'System.IO.FileAttributes' to
'System.Data.SqlTypes.SqlInt32'

How can I convert the Attributes to display an integer value. Clearly the
code below doesn't work. What do I need to do to make it work?

FileInfo f = new FileInfo(FileInfo);
SqlMetaData Attributes;
Attributes = new SqlMetaData("Attributes", SqlDbType.Int);
record = new SqlDataRecord(new SqlMetaData[] { Attributes });
record.SetSqlInt32(0,f.Attributes);
 
N

Nicholas Paldino [.NET/C# MVP]

Greg,

You can just cast the enumeration value, like so:

record.SetSqlInt32(0, (int) f.Attributes);

Hope this helps.
 
G

Guest

That worked great. Thanks.

Nicholas Paldino said:
Greg,

You can just cast the enumeration value, like so:

record.SetSqlInt32(0, (int) f.Attributes);

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Greg Larsen said:
I'm trying write a SQLCLR that returns FileInfo.Attributes property to SQL
Server in a record set and I am getting the following error.

cannot convert from 'System.IO.FileAttributes' to
'System.Data.SqlTypes.SqlInt32'

How can I convert the Attributes to display an integer value. Clearly the
code below doesn't work. What do I need to do to make it work?

FileInfo f = new FileInfo(FileInfo);
SqlMetaData Attributes;
Attributes = new SqlMetaData("Attributes", SqlDbType.Int);
record = new SqlDataRecord(new SqlMetaData[] { Attributes });
record.SetSqlInt32(0,f.Attributes);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top