Posts

Donate

Prevent saving changes that require the table re-creation (SQL Server Error in Updating Primary Key Is Identity)

Good Day! I forgot to set the identity of the primary key of field Id in table Products. After inserting records through insert statements, an error occurs since the column Id does not allow null values. So, I tried changing the Is Identity to true but unluckily I'm stuck with the an error "Prevent saving changes that require the table re-creation". Additional details are as follows: ID field has a constraint called PK_Products. So, after googling a while I came up with series of steps. Note: You have to close the design view of the table in the Management Studio to perform the steps below. -- 1 ALTER TABLE Products DROP CONSTRAINT PK_Products GO -- 2 Alter Table Products Drop Column Id Go -- 3 Alter Table Products Add Id_new Int Identity (1,1) Go -- 4 Exec sp_rename 'Products.Id_new' , 'Id' , 'Column' Go -- 5 ALTER TABLE Products Add CONSTRAINT PK_Products Primary Key (ID) GO

Custom Richtextbox Control With Watermark Support In VB.NET

Here's the VB.NET Version of this Custom Control from this post: Custom Richtextbox control with Watermark Support in C# Option Strict On Option Infer On Imports System.Drawing Imports System.ComponentModel ''' <summary> ''' Set Watermark in RichTextbox. ''' </summary> Public Class WatermarkRichTextbox Inherits Windows.Forms.RichTextBox Private m_watermark As String Private m_watermarkColor As Color Private m_foreColor As Color Private empty As Boolean <Browsable( True )> _ Public Property WatermarkColor() As Color Get Return m_watermarkColor End Get Set (value As Color) m_watermarkColor = value If empty Then MyBase .ForeColor = m_watermarkColor End If End Set End Property <Browsable( True )> _ Public Property Watermark() As String

Custom Richtextbox Control With Watermark Support In C#

There was a solution in MSDN Forums on how to add watermark to a Textbox control. I tried replacing the base class if this will work on a RichTextbox control. After testing, the custom control works as expected. /// <summary> /// Set Watermark in RichTextbox. /// </summary> public class WatermarkRichTextbox : RichTextBox { private string watermark; private Color watermarkColor; private Color foreColor; private bool empty; [Browsable (true)] public Color WatermarkColor { get { return watermarkColor; } set { watermarkColor = value ; if (empty) { base .ForeColor = watermarkColor; } } } [Browsable(true)] public string Watermark { get {

Using PATINDEX() In SQL Server As An Alternative To Embedd Regular Expressions In SQL

Image
This was based on a post from SQL Team on how to grab a 5 digit number from the string field which could utilize a regular expression like this: [0-9 ]{5}. The initial solution was given by a forum member named Kristen. It could extract the 5 digit mark on a string field as shown below: DECLARE @strTest varchar(8000) SELECT @strTest = '\\servername\foldername99999\filename.ext' SELECT [ Position ]=PATINDEX( '%[0-9][0-9][0-9][0-9][0-9]%' , @strTest), [ Before ]= SUBSTRING (@strTest, 1, PATINDEX( '%[0-9][0-9][0-9][0-9][0-9]%' , @strTest)-1), [ After ]= SUBSTRING (@strTest, PATINDEX( '%[0-9][0-9][0-9][0-9][0-9]%' , @strTest), LEN(@strTest)) What if the string field would contain two or more 5 digit information, how can you achieve that? The answer is to include while loop in TSQL and some additional string functions to achieve the desired output. Here's a sample stored procedure: USE TESTDB; GO CREATE PROCEDUR

Set GridView Lines And Pager Background Color In ASP.NET Web Forms

Usually, in ASP.NET 2.0, setting the GridView lines through property should work. However in 4.5, it doesn't seem to render correctly. One blog pointed out to set the gridlines through it's row data bound property as demonstrated on the code below: Aspx Markup <asp:GridView ID= "GridView1" runat= "server" DataSourceID= "SqlDataSource1" BorderColor= "Black" BorderStyle= "Solid" PageSize= "2" AllowPaging= "True" OnRowDataBound= "GridView1_RowDataBound" BackColor= "White" CellPadding= "3" > <FooterStyle BackColor= "White" ForeColor= "#000066" /> <HeaderStyle BackColor= "#006699" Font-Bold= "True" ForeColor= "White" /> <PagerStyle BackColor= "White" ForeColor= "#000066" HorizontalAlign= "Justify" Wrap= "True"

Add Connection On Data Source Controls Not Loading SQL Server 2012 Server Or Instance Name

Image
After installing SQL Server 2012 Developer Edition SP1 on my other laptop, I tried creating an ASP.NET app using SQL DataSource control as the datasource control of the GridView. But to no avail, the mssql server instance doesn't load on the server name dropdown contol as shown below: The hardware specifications are as follows: Windows 8 Pro, Visual Studio 2008/2010/2012 and SQL Server 2012 Developer Edition SP1. However, on my other laptop which has a Windows 8.1 OS, the server names were loaded on the Server Name dropdown control. After experimenting for a few hours, I discovered a simple solution which is to Turn Off The Windows Firewall . After that, my sql server instance is loaded on the control as shown below: Cheers!

'Microsoft.VisualStudio.Editor.Implementation.EditorPackage' package did not load correctly (Visual Studio 2012)

After installing updates for my Windows 8 laptop, I did a restart and opened a Visual Studio 2012 instance. Surprisingly, an error pops-up as stated by the title of this  Post. I did some search on Microsoft Knowledge Base and found a patch for it which is available for download. See the link below: Update for Microsoft Visual Studio 2012 (KB2781514) Greg

CSS Linear Gradients Not Working In Internet Explorer 9 But Working In Firefox And Chrome

Image
I came across with linear gradients not working correctly in IE 9. One solution suggested by a popular forum is to utilize an image as the background of a particular element. Since I'm not a graphic designer, I searched for other solution. I came up with an alternative which is to embed an svg file instead of an image file as an element's background. The css code below won't work in IE 9. body { background-image : -ms-linear-gradient( top , #000, #666); } Here's a solution using .svg file: <svg xmlns= "http://www.w3.org/2000/svg" width= "100%" height= "100%" viewBox= "0 0 1 1" preserveAspectRatio= "none" > <linearGradient id= "g762" gradientUnits= "userSpaceOnUse" x1= "0%" y1= "0%" x2= "0%" y2= "100%" > <stop stop-color= "#000000" offset= "0" /><stop stop-color= "#666666" o

Creating And Consuming Custom Control Events In Windows Forms C#

In my autocomplete textbox control, I have a listbox that shows the suggested items based on user input. However, as a requirement I want to create an event that will trigger once a selection has been done in the listbox and this event will be consumed in the calling program (Main Form). To do that, you must define a custom event. After googling for a while, here are the references that made me accomplish the task: Creating Custom Events in C# Quick and Easy Custom Events Cheers!

Change WPF DataGridCell Background Color Using IVMultiValueConverter

Image
In a post by codefornothing in which He demonstrate the use of IMultiValueConverter using DataTable: The WPF Datagrid and Me , I decided to create a similar post in which the binding source is of type collection (Observable Collection). I encountered a few issues like how to replace the Binding Path values from binding to a strongly type class instead of DataTable. To get things started, here are the snippets: Observable Class public class StudentList : ObservableCollection<Student> { public StudentList() { Add( new Student{ID = 1, Age = 29, Name = "Jerby" , Address= "Cebu" }); Add( new Student{ID = 2, Age = 28, Name = "Renz" , Address= "Cebu" }); Add( new Student{ID = 3, Age = 23, Name = "Aya" , Address= "Leyte" }); Add( new Student{ID = 4, Age = 33, Name = "Jeff" , Address= "Leyte" }); Add( new Student{ID = 5

Donate