Sorry if my subject seems confusing. I have been looking for a way to convert C# datatype into database specific type of MS SQL. For example when I do
dataset.Tables["TableName"].Columns[i].DataType
I would get System.GUID or something like that but what I want is UniqueIdentifier instead of System.GUID. In most cases, I would also want the length of the type like
varchar(1000) and stuff like that. Is there anyway I could convert or get similiar result ? Any sort of input would be much appreciated. Thanks all.
When you are passing parameters to a database, you can specify its parameter type.
So if you are passing in a uniqueidentifer to a sql stored procedure you would create a sqlparameter and set its type to one of the matchin enumeration values in the SqlDbType enum.
How about using SSIS to copy the tables from database to database?
Click "Mark as Answer" on the post that helped you.
This earns you a point and marks your thread as Resolved so we will all know you have been helped.
FAQ on the correct forum http://forums.asp.net/p/1337412/2699239.aspx#2699239
As suggested above, it's not easy to control it in source code. Always, we can take advantage of SQL script. That means you can either execute the SQL script in a query window directly or save and execute it from source code.
Thanks.
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
harrylynn
Member
284 Points
294 Posts
How to convert C# datatype to database type ?
Jan 22, 2010 08:42 PM|LINK
Hi everyone,
Sorry if my subject seems confusing. I have been looking for a way to convert C# datatype into database specific type of MS SQL. For example when I do
I would get System.GUID or something like that but what I want is UniqueIdentifier instead of System.GUID. In most cases, I would also want the length of the type like varchar(1000) and stuff like that. Is there anyway I could convert or get similiar result ? Any sort of input would be much appreciated. Thanks all.
jimmy q
All-Star
54108 Points
3578 Posts
Re: How to convert C# datatype to database type ?
Jan 22, 2010 09:48 PM|LINK
When you are passing parameters to a database, you can specify its parameter type.
So if you are passing in a uniqueidentifer to a sql stored procedure you would create a sqlparameter and set its type to one of the matchin enumeration values in the SqlDbType enum.
harrylynn
Member
284 Points
294 Posts
Re: How to convert C# datatype to database type ?
Jan 23, 2010 07:26 AM|LINK
Thanks for the tips. I think i have to refine my question a bit. What i'm trying to achieve is I have a table in one database and
I'm trying to copy that table into another database. So, in SQL create statement I might need to put like
since i have no idea what would be the columns of the first table, and obviously not each column data type so kinda blur.
Is there anyway to achieve this or umm would it b better off to just use SQL CREATE statement in query editor ? much thanks.
jimmy q
All-Star
54108 Points
3578 Posts
Re: How to convert C# datatype to database type ?
Jan 23, 2010 09:46 PM|LINK
Why dont you just do a table export?
TATWORTH
All-Star
72415 Points
14017 Posts
MVP
Re: How to convert C# datatype to database type ?
Jan 24, 2010 12:33 PM|LINK
How about using SSIS to copy the tables from database to database?
This earns you a point and marks your thread as Resolved so we will all know you have been helped.
FAQ on the correct forum http://forums.asp.net/p/1337412/2699239.aspx#2699239
Wencui Qian ...
All-Star
56784 Points
5796 Posts
Microsoft
Re: How to convert C# datatype to database type ?
Jan 26, 2010 12:28 AM|LINK
Hi harrylynn,
As suggested above, it's not easy to control it in source code. Always, we can take advantage of SQL script. That means you can either execute the SQL script in a query window directly or save and execute it from source code.
Thanks.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
harrylynn
Member
284 Points
294 Posts
Re: How to convert C# datatype to database type ?
Feb 04, 2010 09:14 AM|LINK
Thanks all for all the replies.