Tag: Sql

Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to OFF.

This message is raised when you try to insert values in an identity column. Identity columns are auto incremented by the system and thus, does not allow manual modifications/insertions. To resolve this error, you have to set the Column_Identity ON by using the following syntax. SET IDENTITY_INSERT tblXYZ ON — your insert statement here SET […]

DataGridView datasource : Use BindingSource or direct query ???

LINQ to SQL translates LINQ queries to SQL for execution on a database. The results are strongly typed IEnumerable. Because these objects are ordinary common language runtime (CLR) objects, ordinary object data binding can be used to display the results. On the other hand, sorting and change operations (inserts, updates, and deletes) require additional steps. […]

SQL Compact data and schema script utility

When using a “normal” MsSql database (whatever the version), the management tool allow us to create a “database generation script”. This option does not exists for SqlCE Databases (soooo sad). Here is a little third-party tools that woes the trick… http://exportsqlce.codeplex.com/ Among creating “scripts”, the add-in adds the following menu items to the table context […]

[HowTo] Save Image into SqlCE database

Save into database. //Image to byte[] Image myImage = Image.FromFile(“c:\\xyz.jpg”); System.IO.MemoryStream imgMemoryStream = new System.IO.MemoryStream(); myImage.Save(imgMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] imgByteData = imgMemoryStream.GetBuffer(); //Store image bytes data into database SqlCeConnection scon = new SqlCeConnection(“Data Source=D:\\myDB.sdf”); SqlCeCommand cmd = new SqlCeCommand(“Update ImageTable Set Picture=@myPicture Where Username=’Martin'”, scon); cmd.Parameters.Add(“@myPicture”, SqlDbType.Image).Value = imgByteData; // Or cmd.Parameters.Add(“@myPicture”, SqlDbType.Binary).Value = imgByteData scon.Open(); […]