Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello Umbraco Colleagues,
Can anyone tell me how to get the dbType (Integer, Ntext, Nvarchar... etc.) from a PropertyType?
I've been trying to figure out the way to do this for a long time.
Thanks,
David Hill
Update:
I developed a way to retreive the dbType (Integer, Ntext, Nvarchar... etc.) from a PropertyType.
Here is a C# code snippet:
protected void GetDbType(){ DocumentType docType = new DocumentType(1024); List<PropertyType> propertyTypeList = new List<PropertyType>(); propertyTypeList = docType.PropertyTypes; foreach (PropertyType propertyType in propertyTypeList) { umbraco.interfaces.IDataType dt = propertyType.DataTypeDefinition.DataType; string defId = dt.DataTypeDefinitionId.ToString(); string umbracoDbDSN = System.Configuration.ConfigurationManager.AppSettings["umbracoDbDSN"].ToString(); SqlConnection connection = new SqlConnection(umbracoDbDSN); SqlCommand command = new SqlCommand("SELECT [dbType] FROM [cmsDataType] WHERE [nodeId] = " + defId, connection); SqlDataAdapter adapter = new SqlDataAdapter(command); DataTable table = new DataTable(); adapter.Fill(table); string dbType = table.Rows[0]["dbType"].ToString(); }}
Hope that helps someone someday!
Cheers,
I know it was a while ago, but I recently needed to do the same. I wrote an extension method for DataTypeDefinitions which does the trick nicely:
public static DBTypes GetDBType(this DataTypeDefinition dtd) { var param = umbraco.BusinessLogic.Application.SqlHelper.CreateParameter("@nodeId", dtd.Id); var dbTypeString = umbraco.BusinessLogic.Application.SqlHelper.ExecuteScalar<string>("SELECT [dbType] FROM [cmsDataType] WHERE [nodeId] = @nodeId", param); return (DBTypes) Enum.Parse(typeof (DBTypes), dbTypeString); }
Matt
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
dbType of PropertyType
Hello Umbraco Colleagues,
Can anyone tell me how to get the dbType (Integer, Ntext, Nvarchar... etc.) from a PropertyType?
I've been trying to figure out the way to do this for a long time.
Thanks,
David Hill
Update:
I developed a way to retreive the dbType (Integer, Ntext, Nvarchar... etc.) from a PropertyType.
Here is a C# code snippet:
Hope that helps someone someday!
Cheers,
David Hill
I know it was a while ago, but I recently needed to do the same. I wrote an extension method for DataTypeDefinitions which does the trick nicely:
Matt
is working on a reply...