Skip to main content

Posts

Showing posts with the label sharing

Dropdown List from object List in MVC View

In previous months, i have opportunity to play along with MVC after a while using EF Code First and MVC 5. So today the snippet about creating DropdownList from object List rather than List of SelectListItem let's say u have this Company Class [Key] public int CompanyId { get; set; } public string Name { get; set; } public string Code { get; set; } and u want to display dropdown list based on Code as Text and Id as Value in the View u create a SelectList based on that field @Html.LabelFor(model => model.Brand.Company, htmlAttributes: new { @class = "control-label col-md-2" }) @Html.DropDownList("selectedCompany", Model.Companies.Select(_ => new SelectListItem { Text = _.Code, Value = _.CompanyId.ToString(), Selected = _.CompanyId.ToString() == Model.Brand.Company.CompanyId.ToString() }) ) the Model is a simple ViewModel that have Brands and Brand object sorry for the format, can not make it right :D

sp_msforeachtable - Quick counting table rows

i just starting to play along with SSIS and SSAS and i came up with this trick to show wether my data has been populate into staging or data warehouse table so here is the script EXEC sp_MSForEachTable " DECLARE @count AS INT SET @count=0 SELECT @count = ISNULL(SUM(1), 0) FROM ? PRINT ""?: "" + CONVERT(VARCHAR, @Count) , @whereand = "ORDER BY 1" "  until then

sp_msforeachtable - Delete data in all tables in SQL Server database

hi all, just remember to post this useful tips -- disable all constraints EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all" -- delete data in all tables EXEC sp_MSForEachTable "DELETE FROM ?" -- enable all constraints exec sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all" --if some of the tables have identity columns we may want to reseed them EXEC sp_MSforeachtable "DBCC CHECKIDENT ( '?', RESEED, 0)" see u then

sp_MsForEachTable - compare data between tables

usually i will using temporary table to build dynamic query to compare the value for two indentical database between two servers but few weeks ago i know undocumented sp_msforeachtable stored procedure and gain some advantage for using it exec sp_MSforeachtable  @command1 = ' IF EXISTS( SELECT top 1 * FROM [server2].db_name.? EXCEPT  SELECT top 1 * FROM ?   ) PRINT ''?'' ' just make sure u use "." in first syntax because sp_msforeachtable return "dbo.table_name" for parameters reference please see this link see u

create ClickOnce shortcut at Startup

currently there are needs to add some shortcut based on ClickOnce Application that being deployed, it's obvious we can't create it manually because of the installation path here is some remedy :D, u need to add reference to System.Deployment, System.IO,  System.Reflection  if (ApplicationDeployment.IsNetworkDeployed) { string publisherName = ((AssemblyCompanyAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyCompanyAttribute), false)).Company; string productName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; string startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); startupPath = Path.Combine(startupPath, productName) + ".appref-ms"; if (!File.Exists(startupPath)) { string allProgramsPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs); string shortcutPath = Path.Combine(allProgramsPath, publisherName); shortcutPath = Path.Combine...

Force Application update in ClickOnce deployment

the key is to set minimum requirement version to be exactly like the one u published right now to remove the update popup dialog when starting clickonce program just make sure the version is the same between Publish version and Update the Project properties - Publish until then

WCF: The underlying connection was closed

hi, just got an error for couple of days when try to return a model contain child record using Entity Framework and DBContext i have this Role class that contain list of User within that Role so when i try to get specific Role along with the User it give me an error "The underlying connection was closed " after searching alot i came up with this great solution disabled proxy creation and lazy loading or  manually in Entity DBContext constructor it run succesfully and can return UserInRole but if i filled up the table then the error comes, so we need to  Preserving Object Reference in WCF  but i came with this very useful  Andrey Chabster Blog  that using custom attribute that needed for the Service contract and Operation contract  until then

Enable Samesite for the .NET Framework 3.5 SP1 bootstrapper package

hi, i recently got an error when trying to publish ClickOnce app that run under 3.5 framework. the error said " The install location for prerequisites has not been set to 'component vendor's web site' and the file 'dotNetFx35setup.exe' in item 'Microsoft.Net.Framework.3.5.SP1' cannot be located on disk." so i found the solution for this one Update the Package Data Open the [Program Files]\Microsoft SDKs\Windows\v6.0A\ Bootstrapper \Packages\DotNetFx35SP1 folder or % ProgramFiles (x86)%\Microsoft SDKs\Windows\v6.0A\ Bootstrapper \Packages\DotNetFx35SP1 on x64 operating systems Edit the Product.xml file in Notepad. Paste the following into the <  PackageFiles  > element:  < PackageFile  Name="TOOLS\clwireg.exe"/> < PackageFile  Name="TOOLS\clwireg_x64.exe"/> < PackageFile  Name="TOOLS\clwireg_ia64.exe"/> Find the element for <  PackageFile  Name="dotNetFX30\XPSEP...

Add network Share Printer in Windows that using differen version of Windows

Here is the step-by-step description 1) Share Permissions  1. On explorer, go to C:\windows\system32\spool\PRINTERS  2. Right click, Properties  3. Sharing tab  4. Advanced Sharing  5. Check "Share this folder"  6. Permissions  7. Grant everyone Full Control  2) NTFS Permissions  1. On explorer, go to C:\windows\system32\spool\printers  2. Right click, Properties  3. Security tab  4. Edit  5. Add  6. Advanced  7. Find Now  8. Choose "NETWORK"  9. OK  10. Grant NETWORK Full Control  read here for details  see u next time