Tag: c#

Entity framework core: The property expression 'xx' is not valid. The expression should represent a property access: 't => t.MyProperty'

Trying to query with where clause at the leaf level in entity framework core but getting this error: Unhandled Exception: System.ArgumentException: The property expression ‘c => {from Child t in c.Children where ([t].Name != “NoInc lude”) select [t]}’ is not valid. The expression should represent a property access: ‘t => t.MyProperty’. For more information on […]

How to backup only table data from SQL Server 2008 R2 using C#

I developed a good application with backup and restore feature. It works fine. every time I added new features to its SQL Server 2008 R2 database, for example add a new stored procedure or user-defined table type to upgrade my software. My backup function is this: protected int BackUpDataBase(string dbName, string address) { try { […]

What's the best way to calculate similarity between rows in a table based on association?

Suppose each Person has a collection of favorite Books. So I have a table for: Person Book The association between Person and Book (joint table for MxN) I want to fetch the Persons that are similar to a Person1 based on the favorite Books overlaping. That is: The more books they have in common, the […]

How to tell Linq which Database Version to use

i am using sql server 2005 and I think Linq generating queries for a different database version. I got the query string that linq was producing and pasted the linq directly in SQL Server Management studio and it failed with many errors. But the query works well if Linq is used. Any ideas what could […]

save user profile image to database

How can I dynamically insert images when user uploads an image file to SQL Server 2005 with C# in ASP.NET? This is to let users upload their profile photos in my web app. Is it very different from how it is done for windows app with C#?

Data source controls and parameter type conversion

Q1 – In the code example below runtime converts a value between two incompatible types: <SelectParameters> <asp:Parameter Name=”City” Type=”Int32″ /> </SelectParameters> protected void SqlDataSource2_Selecting(object sender, SqlDataSourceSelectingEventArgs e) {e.Command.Parameters[“@City”].Value = “100”;} Exception I got: “Conversion failed when converting the nvarchar value ‘Seattle’ to data type int.” A) The above exception suggests that runtime did manage to […]

Create, Approve, Edit, Approve pattern for site content

I’m working on a modification to a site to allowing users to enter content. However, once they’ve created that content it needs to be approved before it can be published. This is fairly easy to achieve by having a “moderate” bit set in the record for that content and only one table is needed. Now […]

How to log SQL output to text file on client from C#

I have a large auditing stored procedure that prints values and runs some SELECT statements. When running within SQL Management Studio we have the use select to display “Results to Text” so all of the SQL results and print statement display in one place. Now I need to have some C# code also call this […]

How to fast fill MS Sql 2005 wit data in c#

I crate temporary table in c# (one column, type int), later I want to put ~40 000 values inside (it will be constantly changing). What is the fastest way of doing it ?

C# Display Join Query in DataGridView at designTime using TableAdapter, etc

I have a DataGridView I also have some tableAdapters (groupTableAdapter, userTableAdapter) generated from sqlserver database. I have created a JOIN query in userTableAdapter that shows users with their correspoding groupname. Of course, I’ve got the classic warning Visual Studio throws regarding it is not the original bla bla bla… after I generated the Fill and […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.